Dolt System Tables

Table of contents

Dolt System Tables

dolt_branches

dolt_branches contains information about branches known to the database.
Branches can be created, modified, or deleted with INSERT, UPDATE, or DELETE statements.
Because the branch information is global to all clients, not just your session, it's recommended to lock the table before modifying it.

Schema

1
+------------------------+----------+
2
| Field | Type |
3
+------------------------+----------+
4
| name | TEXT |
5
| hash | TEXT |
6
| latest_committer | TEXT |
7
| latest_committer_email | TEXT |
8
| latest_commit_date | DATETIME |
9
| latest_commit_message | TEXT |
10
+------------------------+----------+
Copied!

Example Queries

Get all the branches.
1
SELECT *
2
FROM dolt_branches
Copied!
1
+--------+----------------------------------+------------------+------------------------+-----------------------------------+-------------------------------+
2
| name | hash | latest_committer | latest_committer_email | latest_commit_date | latest_commit_message |
3
+--------+----------------------------------+------------------+------------------------+-----------------------------------+-------------------------------+
4
| 2011 | t2sbbg3h6uo93002frfj3hguf22f1uvh | bheni | [email protected] | 2020-01-22 20:47:31.213 +0000 UTC | import 2011 column mappings |
5
| 2012 | 7gonpqhihgnv8tktgafsg2oovnf3hv7j | bheni | [email protected] | 2020-01-22 23:01:39.08 +0000 UTC | import 2012 allnoagi data |
6
| 2013 | m9seqiabaefo3b6ieg90rr4a14gf6226 | bheni | [email protected] | 2020-01-22 23:50:10.639 +0000 UTC | import 2013 zipcodeagi data |
7
| 2014 | v932nm88f5g3pjmtnkq917r2q66jm0df | bheni | [email protected] | 2020-01-23 00:00:43.673 +0000 UTC | update 2014 column mappings |
8
| 2015 | c7h0jc23hel6qbh8ro5ertiv15to9g9o | bheni | [email protected] | 2020-01-23 00:04:35.459 +0000 UTC | import 2015 allnoagi data |
9
| 2016 | 0jntctp6u236le9qjlt9kf1q1if7mp1l | bheni | [email protected] | 2020-01-28 20:38:32.834 +0000 UTC | fix allnoagi zipcode for 2016 |
10
| 2017 | j883mmogbd7rg3cfltukugk0n65ud0fh | bheni | [email protected] | 2020-01-28 16:43:45.687 +0000 UTC | import 2017 allnoagi data |
11
| master | j883mmogbd7rg3cfltukugk0n65ud0fh | bheni | [email protected] | 2020-01-28 16:43:45.687 +0000 UTC | import 2017 allnoagi data |
12
+--------+----------------------------------+------------------+------------------------+-----------------------------------+-------------------------------+
Copied!
Get the current branch for a database named "mydb".
1
SELECT *
2
FROM dolt_branches
3
WHERE hash = @@mydb_head
Copied!
1
+--------+----------------------------------+------------------+------------------------+-----------------------------------+-------------------------------+
2
| name | hash | latest_committer | latest_committer_email | latest_commit_date | latest_commit_message |
3
+--------+----------------------------------+------------------+------------------------+-----------------------------------+-------------------------------+
4
| 2016 | 0jntctp6u236le9qjlt9kf1q1if7mp1l | bheni | [email protected] | 2020-01-28 20:38:32.834 +0000 UTC | fix allnoagi zipcode for 2016 |
5
+--------+----------------------------------+------------------+------------------------+-----------------------------------+-------------------------------+
Copied!
Create a new commit, and then create a branch from that commit
1
SET @@mydb_head = COMMIT("my commit message")
2
3
INSERT INTO dolt_branches (name, hash)
4
VALUES ("my branch name", @@mydb_head);
Copied!

dolt_commit_diff_$TABLENAME

For every user table named $TABLENAME, there is a queryable system table named dolt_commit_diff_$TABLENAME which can be queried to see how a table has changed between two commits (regardless of which branch the user is currently using).
For each pair of commits in the database history, the diff tables will have zero or more rows, each of which represents a row that is different between the two commits, with its old and new values.

Schema

1
+-------------+------+
2
| field | type |
3
+-------------+------+
4
| from_commit | TEXT |
5
| to_commit | TEXT |
6
| diff_type | TEXT |
7
| other cols | |
8
+-------------+------+
Copied!
The remaining columns will be dependent on the schema of the user table. For every column X in your table at from_commit, there will be a column in the result set named from_$X with the same type as X, and for every column Y in your table at to_commit there will be a column in the result set named to_$Y with the same type as Y. The from_commit and to_commit parameters must both be filled.
dolt_commit_diff_$TABLENAME is more similar to the dolt diff CLI command than the dolt_diff_$TABLENAME table. It represents the two-dot diff between the two commits provided.

Example Schema

Let us consider a simple example with a table that has two columns. Consider the table
1
+--------------+
2
| field | type |
3
+--------------+
4
| pk | int |
5
| val | int |
6
+--------------+
Copied!
We see that the structure of the dolt_commit_diff_$TABLENAME will be.
1
+------------------+----------+
2
| field | type |
3
+------------------+----------+
4
| to_pk | int |
5
| to_val | int |
6
| to_commit | longtext |
7
| to_commit_date | datetime |
8
| from_pk | int |
9
| from_val | int |
10
| from_commit | longtext |
11
| from_commit_date | datetime |
12
+------------------+----------+
Copied!

Query Details

Let us now consider the following branch structure:
1
A---B---C feature
2
/
3
D---E---F---G master
Copied!
We can use the above table to represent two types of diffs, a two-point diff and a three-point diff. In a two-point diff we want to see the difference in rows between Point C and Point G. To do that we can simply do
1
SELECT * from dolt_commif_diff_$TABLENAME where to_commit=HASHOF('feature') and from_commit = HASHOF('master');
Copied!
We can also compute a three-point diff using this table. In a three-point diff we want to see how our feature branch has diverged from our common ancestor E. We can do the following queries
1
SELECT * FROM dolt_commit_diff_$TABLENAME WHERE to_commit=HASHOF('feature') and from_commit=dolt_merge_base('master', 'feature');
Copied!
The function dolt_merge_base computes the closest ancestor E between master and feature.

Additional Notes

There is one special to_commit value WORKING which can be used to see what changes are in the working set that have yet to be committed to HEAD. It is often useful to use the HASHOF() function to get the commit hash of a branch, or an ancestor commit. The above table requires both from_commit and to_commit to be filled.

dolt_diff_$TABLENAME

For every user table named $TABLENAME, there is a queryable system table named dolt_diff_$TABLENAME which can be queried to see how rows have changed over time. Each row in the result set represents a row that has changed between two commits. Compared to the dolt_commit_diff_$TABLENAME the dolt_diff_$TABLENAME focuses on how a particular row has evolved over time through the current branch.

Schema

Every Dolt diff table will have the columns
1
+-------------+------+
2
| field | type |
3
+-------------+------+
4
| from_commit | TEXT |
5
| to_commit | TEXT |
6
| diff_type | TEXT |
7
| other cols | |
8
+-------------+------+
Copied!
The remaining columns will be dependent on the schema of the user table. For every column X in your table at from_commit, there will be a column in the result set named from_$X with the same type as X, and for every column Y in your table at to_commit there will be a column in the result set named to_$Y with the same type as Y.

Example Schema

For a hypothetical table named states with a schema that changes between from_commit and to_commit as shown below
1
# schema at from_commit # schema at to_commit
2
+------------+--------+ +------------+--------+
3
| field | type | | field | type |
4
+------------+--------+ +------------+--------+
5
| state | TEXT | | state | TEXT |
6
| population | BIGINT | | population | BIGINT |
7
+------------+--------+ | area | BIGINT |
8
+-------------+-------+
Copied!
The schema for dolt_diff_states would be
1
+-----------------+--------+
2
| field | type |
3
+-----------------+--------+
4
| from_state | TEXT |
5
| to_state | TEXT |
6
| from_population | BIGINT |
7
| to_population | BIGINT |
8
| to_state | TEXT |
9
| from_commit | TEXT |
10
| to_commit | TEXT |
11
| diff_type | TEXT |
12
+-----------------+--------+
Copied!

Query Details

Doing a SELECT * query for a diff table will show you every change that has occurred to each row for every commit in this branches history. Using to_commit and from_commit you can limit the data to specific commits. There is one special to_commit value WORKING which can be used to see what changes are in the working set that have yet to be committed to HEAD. It is often useful to use the HASHOF() function to get the commit hash of a branch, or an ancestor commit. To get the differences between the last commit and it's parent you could use to_commit=HASHOF("HEAD") and from_commit=HASHOF("HEAD^")
For each row the field diff_type will be one of the values added, modified, or removed. You can filter which rows appear in the result set to one or more of those diff_type values in order to limit which types of changes will be returned.

Example Query

Taking the dolthub/wikipedia-ngrams data repository from DoltHub as our example, the following query will retrieve the bigrams whose total counts have changed the most between 2 versions.
1
SELECT from_bigram, to_bigram, from_total_count, to_total_count, ABS(to_total_count-from_total_count) AS delta
2
FROM dolt_diff_bigram_counts
3
WHERE from_commit = HASHOF("HEAD~3") AND diff_type = "modified"
4
ORDER BY delta DESC
5
LIMIT 10;
Copied!
1
+-------------+-------------+------------------+----------------+-------+
2
| from_bigram | to_bigram | from_total_count | to_total_count | delta |
3
+-------------+-------------+------------------+----------------+-------+
4
| of the | of the | 21566470 | 21616678 | 50208 |
5
| _START_ The | _START_ The | 19008468 | 19052410 | 43942 |
6
| in the | in the | 14345719 | 14379619 | 33900 |
7
| _START_ In | _START_ In | 8212684 | 8234586 | 21902 |
8
| to the | to the | 7275659 | 7291823 | 16164 |
9
| _START_ He | _START_ He | 5722362 | 5737483 | 15121 |
10
| at the | at the | 4273616 | 4287398 | 13782 |
11
| for the | for the | 4427780 | 4438872 | 11092 |
12
| and the | and the | 4871852 | 4882874 | 11022 |
13
| is a | is a | 4632620 | 4643068 | 10448 |
14
+-------------+-------------+------------------+----------------+-------+
Copied!

dolt_docs

dolt_docs stores the contents of Dolt docs (LICENSE.md, README.md).
You can modify the contents of these files via SQL, but you are not guaranteed to see these changes reflected in the files on disk.

Schema

1
+----------+------+
2
| field | type |
3
+----------+------+
4
| doc_name | text |
5
| doc_text | text |
6
+----------+------+
Copied!

Usage

Dolt users do not have to be familiar with this system table in order to make a LICENSE.md or README.md. Simply run dolt init or touch README.md and touch LICENSE.md from a Dolt repository to get started. Then, dolt add and dolt commit the docs like you would a table.

dolt_history_$TABLENAME

For every user table named $TABLENAME, there is a queryable system table named dolt_history_$TABLENAME which can be queried to find a row's value at every commit in the current branches commit graph.

Schema

Every Dolt history table will have the columns
1
+-------------+----------+
2
| field | type |
3
+-------------+----------+
4
| commit_hash | TEXT |
5
| committer | TEXT |
6
| commit_date | DATETIME |
7
| other cols | |
8
+-------------+----------+
Copied!
The rest of the columns will be the superset of all columns that have existed throughout the history of the table.

Example Schema

For a hypothetical data repository with the following commit graph:
1
A
2
/ \
3
B C
4
\
5
D
Copied!
Which has a table named states with the following schemas at each commit:
1
# schema at A # schema at B # schema at C # schema at D
2
+------------+--------+ +------------+--------+ +------------+--------+ +------------+--------+
3
| field | type | | field | type | | field | type | | field | type |
4
+------------+--------+ +------------+--------+ +------------+--------+ +------------+--------+
5
| state | TEXT | | state | TEXT | | state | TEXT | | state | TEXT |
6
| population | BIGINT | | population | BIGINT | | population | BIGINT | | population | BIGINT |
7
+------------+--------+ | capital | TEXT | | area | BIGINT | | area | BIGINT |
8
+------------+--------+ +------------+--------+ | counties | BIGINT |
9
+------------+--------+
Copied!
The schema for dolt_history_states would be:
1
+-------------+----------+
2
| field | type |
3
+-------------+----------+
4
| state | TEXT |
5
| population | BIGINT |
6
| capital | TEXT |
7
| area | BIGINT |
8
| counties | BIGINT |
9
| commit_hash | TEXT |
10
| committer | TEXT |
11
| commit_date | DATETIME |
12
+-------------+----------+
Copied!

Example Query

Taking the above table as an example. If the data inside dates for each commit was:
  • At commit "A" the state data from 1790
  • At commit "B" the state data from 1800
  • At commit "C" the state data from 1800
  • At commit "D" the state data from 1810
1
SELECT *
2
FROM dolt_history_states
3
WHERE state = "Virginia";
Copied!
1
+----------+------------+----------+--------+----------+-------------+-----------+---------------------------------+
2
| state | population | capital | area | counties | commit_hash | committer | commit_date |
3
+----------+------------+----------+--------+----------+-------------+-----------+---------------------------------+
4
| Virginia | 691937 | <NULL> | <NULL> | <NULL> | HASH_AT(A) | billybob | 1790-01-09 00:00:00.0 +0000 UTC |
5
| Virginia | 807557 | Richmond | <NULL> | <NULL> | HASH_AT(B) | billybob | 1800-01-01 00:00:00.0 +0000 UTC |
6
| Virginia | 807557 | <NULL> | 42774 | <NULL> | HASH_AT(C) | billybob | 1800-01-01 00:00:00.0 +0000 UTC |
7
| Virginia | 877683 | <NULL> | 42774 | 99 | HASH_AT(D) | billybob | 1810-01-01 00:00:00.0 +0000 UTC |
8
+----------+------------+----------+--------+----------+-------------+-----------+---------------------------------+
9
10
# Note in the real result set there would be actual commit hashes for each row. Here I have used notation that is
11
# easier to understand how it relates to our commit graph and the data associated with each commit above
Copied!

dolt_commit_ancestors

The dolt_commit_ancestors table records the ancestors for every commit in the database. Each commit has one or two ancestors, two in the case of a merge commit.

Schema

Each commit hash has one or two entries in the table, depending on whether it has one or two parent commits. The root commit of the database has a NULL parent. For merge commits, the merge base will have parent_index 0, and the commit merged will have parent_index 1.
1
+--------------+------+------+-----+---------+-------+
2
| Field | Type | Null | Key | Default | Extra |
3
+--------------+------+------+-----+---------+-------+
4
| commit_hash | text | NO | PRI | | |
5
| parent_hash | text | NO | PRI | | |
6
| parent_index | int | NO | PRI | | |
7
+--------------+------+------+-----+---------+-------+
Copied!

dolt_log

dolt_log contains the commit log, with contents identical to the dolt log command on the CLI.

Schema

1
+-------------+----------+
2
| field | type |
3
+-------------+--------- +
4
| commit_hash | text |
5
| committer | text |
6
| email | text |
7
| date | datetime |
8
| message | text |
9
+-------------+--------- +
Copied!

Example Query

1
SELECT *
2
FROM dolt_log
3
WHERE committer = "bheni" and date > "2019-04-01"
4
ORDER BY "date";
Copied!
1
+----------------------------------+-----------+--------------------+-----------------------------------+---------------+
2
| commit_hash | committer | email | date | message |
3
+----------------------------------+-----------+--------------------+-----------------------------------+---------------+
4
| qi331vjgoavqpi5am334cji1gmhlkdv5 | bheni | [email protected] | 2019-06-07 00:22:24.856 +0000 UTC | update rating |
5
| 137qgvrsve1u458briekqar5f7iiqq2j | bheni | [email protected] | 2019-04-04 22:43:00.197 +0000 UTC | change rating |
6
| rqpd7ga1nic3jmc54h44qa05i8124vsp | bheni | [email protected] | 2019-04-04 21:07:36.536 +0000 UTC | fixes |
7
+----------------------------------+-----------+--------------------+-----------------------------------+---------------+
Copied!

dolt_status

dolt_status returns the status of the database session, analogous to running dolt status from the command line.

Schema

1
+------------+---------+------+-----+
2
| Field | Type | Null | Key |
3
+------------+---------+------+-----+
4
| table_name | text | NO | PRI |
5
| staged | tinyint | NO | |
6
| status | text | NO | |
7
+------------+---------+------+-----+
Copied!

Example Query

1
SELECT *
2
FROM dolt_status
3
WHERE staged=false;
Copied!
1
+------------+--------+-----------+
2
| table_name | staged | status |
3
+------------+--------+-----------+
4
| one_pk | false | new table |
5
+------------+--------+-----------+
Copied!

dolt_conflicts

dolt_conflicts is a system table that has a row for every table in the working set that has an unresolved merge conflict.
1
+---------------+-----------------+------+-----+---------+-------+
2
| Field | Type | Null | Key | Default | Extra |
3
+---------------+-----------------+------+-----+---------+-------+
4
| table | text | NO | PRI | | |
5
| num_conflicts | bigint unsigned | NO | | | |
6
+---------------+-----------------+------+-----+---------+-------+
Copied!
Query this table when resolving conflicts in a SQL session. For more information on resolving merge conflicts in SQL, see docs for the dolt_conflicts_$TABLENAME tables.

dolt_conflicts_$TABLENAME

For each table $TABLENAME in conflict after a merge, there is a corresponding system table named dolt_conflicts_$TABLENAME. The schema of each such table contains three columns for each column in the actual table, representing each row in conflict for each of ours, theirs, and base values.
Consider a table mytable with this schema:
1
+-------+------+------+-----+---------+-------+
2
| Field | Type | Null | Key | Default | Extra |
3
+-------+------+------+-----+---------+-------+
4
| a | int | NO | PRI | | |
5
| b | int | YES | | | |
6
+-------+------+------+-----+---------+-------+
Copied!
If we attempt a merge that creates conflicts in this table, I can examine them with the following query:
1
mydb> select * from dolt_conflicts_mytable;
2
+--------+--------+-------+-------+---------+---------+
3
| base_a | base_b | our_a | our_b | their_a | their_b |
4
+--------+--------+-------+-------+---------+---------+
5
| NULL | NULL | 3 | 3 | 3 | 1 |
6
| NULL | NULL | 4 | 4 | 4 | 2 |
7
+--------+--------+-------+-------+---------+---------+
Copied!
To mark conflicts as resolved, delete them from the corresponding table. To effectively keep all our values, I would simply run:
1
mydb> delete from dolt_conflicts_mytable;
Copied!
If I wanted to keep all their values, I would first run this statement:
1
mydb> replace into mytable (select their_a, their_b from dolt_conflicts_mytable);
Copied!
And of course you can use any combination of ours, theirs and base rows in these replacements.

dolt_constraint_violations

The dolt_constraint_violations system table contains one row for every table that has a constraint violation introduced by a merge. Dolt enforces constraints (such as foreign keys) during normal SQL operations, but it's possible that a merge puts one or more tables in a state where constraints no longer hold. For example, a row deleted in the merge base could be referenced via a foreign key constraint by an added row in the merged commit. Use dolt_constraint_violations to discover such violations.

Schema

1
+----------------+-----------------+------+-----+---------+-------+
2
| Field | Type | Null | Key | Default | Extra |
3
+----------------+-----------------+------+-----+---------+-------+
4
| table | text | NO | PRI | | |
5
| num_violations | bigint unsigned | NO | | | |
6
+----------------+-----------------+------+-----+---------+-------+
Copied!

dolt_constraint_violations_$TABLENAME

For each table $TABLENAME with a constraint violation after a merge, there is a corresponding system table named dolt_constraint_violations_$TABLENAME. Each row in the table represents a constraint violation that must be resolved via INSERT, UPDATE, or DELETE statements. Resolve each constraint violation before committing the result of the merge that introduced them.

Schema

For a hypothetical table a with the following schema:
1
+-------+------------+------+-----+---------+-------+
2
| Field | Type | Null | Key | Default | Extra |
3
+-------+------------+------+-----+---------+-------+
4
| x | bigint | NO | PRI | | |
5
| y | varchar(1) | YES | | | |
6
+-------+------------+------+-----+---------+-------+
Copied!
dolt_constraint_violations_a will have the following schema:
1
+----------------+-------------------------------------------------------+------+-----+---------+-------+
2
| Field | Type | Null | Key | Default | Extra |
3
+----------------+-------------------------------------------------------+------+-----+---------+-------+
4
| violation_type | enum('foreign key','unique index','check constraint') | NO | PRI | | |
5
| x | bigint | NO | PRI | | |
6
| y | varchar(1) | YES | | | |
7
| violation_info | json | YES | | | |
8
+----------------+-------------------------------------------------------+------+-----+---------+-------+
Copied!
Each row in the table represents a row in the primary table that is in violation of one or more constraint violations. The violation_info field is a JSON payload describing the violation.
As with dolt_conflicts, delete rows from the corresponding dolt_constraint_violations table to signal to dolt that you have resolved any such violations before committing.

dolt_procedures

dolt_procedures stores each stored procedure that has been created on the database.
The values in this table are implementation details associated with the storage of stored procedures. It is recommended to use built-in SQL statements for examining and modifying stored procedures rather than using this table directly.

Schema

1
+-------------+----------+
2
| field | type |
3
+-------------+----------+
4
| name | longtext |
5
| create_stmt | longtext |
6
| created_at | datetime |
7
| modified_at | datetime |
8
+-------------+----------+
Copied!
When using the standard CREATE PROCEDURE workflow, the name column will always be lowercase. Dolt assumes that name is always lowercase as a result, and manually inserting a stored procedure must also have a lowercase name. Otherwise, it will be invisible to some operations, such as DROP PROCEDURE.

Example Query

1
CREATE PROCEDURE p1(x INT) SELECT x;
2
SELECT * FROM dolt_procedures;
Copied!
1
+------+-------------------------------------+-------------------------------+-------------------------------+
2
| name | create_stmt | created_at | modified_at |
3
+------+-------------------------------------+-------------------------------+-------------------------------+
4
| p1 | CREATE PROCEDURE p1(x INT) SELECT x | 2021-03-04 00:00:000+0000 UTC | 2021-03-04 00:00:000+0000 UTC |
5
+------+-------------------------------------+-------------------------------+-------------------------------+
Copied!

dolt_schemas

dolt_schemas stores SQL schema fragments for a dolt database that are versioned alongside the database itself. Certain DDL statements will modify this table and the value of this table in a SQL session will affect what database entities exist in the session.
The values in this table are implementation details associated with the storage of certain schema elements. It is recommended to use built-in SQL statements for examining and modifying schemas, rather than using this table directly.

Schema

1
+-------------+----------+
2
| field | type |
3
+-------------+--------- +
4
| type | text |
5
| name | text |
6
| fragment | text |
7
+-------------+--------- +
Copied!
Currently on view definitions are stored in dolt_schemas. type is currently always the string view. name is the name of the view as supplied in the CREATE VIEW ... statement. fragment is the select fragment that the view is defined as.
The values in this table are partly implementation details associated with the implementation of the underlying database objects.

Example Query

1
CREATE VIEW four AS SELECT 2+2 FROM dual;
2
SELECT * FROM dolt_schemas;
Copied!
1
+------+------+----------------------+
2
| type | name | fragment |
3
+------+------+----------------------+
4
| view | four | select 2+2 from dual |
5
+------+------+----------------------+
Copied!

dolt_remotes

dolt_remotes returns the remote subcontents of the repo_state.json, similar to running dolt remote -v from the command line.
The dolt_remotes table is currently read only. Use the CLI dolt remote functions to add, update or delete remotes.

Schema

1
+-------------+------+------+-----+---------+-------+
2
| Field | Type | Null | Key | Default | Extra |
3
+-------------+------+------+-----+---------+-------+
4
| name | text | NO | PRI | | |
5
| url | text | NO | | | |
6
| fetch_specs | json | YES | | | |
7
| params | json | YES | | | |
8
+-------------+------+------+-----+---------+-------+
Copied!

Example Query

1
SELECT *
2
FROM dolt_remotes
3
WHERE name = 'origin';
Copied!
1
+--------+-----------------------------------------+--------------------------------------+--------+
2
| name | url | fetch_specs | params |
3
+--------+-----------------------------------------+--------------------------------------+--------+
4
| origin | file:///go/github.com/dolthub/dolt/rem1 | [refs/heads/*:refs/remotes/origin/*] | map[] |
5
+--------+-----------------------------------------+--------------------------------------+--------+
Copied!
Last modified 1mo ago