System Tables

Table of contents

Database Metadata:
Database History:
Working Set Metadata:
Constraint Validation:

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
| main | 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_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 database to get started. Then, dolt add and dolt commit the docs like you would a table.

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_query_catalog

The dolt_query_catalog system table stores named queries for your database. Like all data stored in Dolt, these named queries are versioned alongside your data, so after you create, modify, or remove a named query, you'll need to commit that change to save it. You can use the Dolt CLI to save and execute named queries or you can use the dolt_query_catalog system table directly to add, modify, or delete named queries. All named queries are displayed in the Queries tab of your database on DoltHub.

Schema

1
+---------------+-----------------+------+-----+---------+-------+
2
| Field | Type | Null | Key | Default | Extra |
3
+---------------+-----------------+------+-----+---------+-------+
4
| id | varchar(16383) | NO | PRI | | |
5
| display_order | bigint unsigned | NO | | | |
6
| name | varchar(16383) | YES | | | |
7
| query | varchar(16383) | YES | | | |
8
| description | varchar(16383) | YES | | | |
9
+---------------+-----------------+------+-----+---------+-------+
Copied!

Example Query

Using the jfulghum/iris-flower-dataset from DoltHub as an example, you can create a named query using the CLI, or by directly inserting into the dolt_query_catalog table.
1
> dolt sql -q "select distinct(class) from classified_measurements where petal_length_cm > 5" \
2
-s "Large Irises" -m "Query to identify iris species with the largest recorded petal lengths"
Copied!
After creating a named query, you can view it in the dolt_query_catalog table:
1
> select * from dolt_query_catalog;
2
+--------------+---------------+--------------+-------------------------------------------------------------------------------+------------------------------------------------------------------------+
3
| id | display_order | name | query | description |
4
+--------------+---------------+--------------+-------------------------------------------------------------------------------+------------------------------------------------------------------------+
5
| Large Irises | 1 | Large Irises | select distinct(class) from classified_measurements where petal_length_cm > 5 | Query to identify iris species with the largest recorded petal lengths |
6
+--------------+---------------+--------------+-------------------------------------------------------------------------------+------------------------------------------------------------------------+
Copied!
Then you can use the dolt CLI to execute it:
1
> dolt sql -x "Large Irises"
2
Executing saved query 'Large Irises':
3
select distinct(class) from classified_measurements where petal_length_cm > 5
4
+------------+
5
| class) |
6
+------------+
7
| versicolor |
8
| virginica |
9
+------------+
Copied!
Last, but not least, if you want to persist that named query, be sure to commit your change to the dolt_query_catalog table.
1
dolt add dolt_query_catalog
2
dolt commit -m "Adding new named query"
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!

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_blame_$tablename

For every user table that has a primary key, there is a queryable system view named dolt_blame_$tablename which can be queried to see the user and commit responsible for the current value of each row. This is equivalent to the dolt blame CLI command. Tables without primary keys will not have an associated dolt_blame_$tablename.

Schema

The dolt_blame_$tablename system view has the following columns:
1
+-------------------+----------+
2
| field | type |
3
+-------------------+----------+
4
| commit | text |
5
| commit_date | datetime |
6
| committer | text |
7
| email | text |
8
| message | text |
9
| primary key cols | |
10
+-------------------+----------+
Copied!
The remaining columns are dependent on the schema of the user table. Every column from the primary key of your table will be included in the dolt_blame_$tablename system table.

Query Details

Executing a SELECT * query for a dolt_blame_$tablename system view will show you the primary key columns for every row in the underlying user table and the commit metadata for the last commit that modified that row. Note that if a table has any uncommitted changes in the working set, those will not be displayed in the dolt_blame_$tablename system view.
dolt_blame_$tablename is only available for tables with a primary key. Attempting to query dolt_blame_$tablename for a table without a primary key will return an error message.

Example Query

Consider the following example table app_config that holds configuration data:
1
> describe app_config;
2
+--------+----------+------+-----+---------+-------+
3
| Field | Type | Null | Key | Default | Extra |
4
+--------+----------+------+-----+---------+-------+
5
| id | bigint | NO | PRI | | |
6
| name | longtext | NO | | | |
7
| value | longtext | NO | | | |
8
+--------+----------+------+-----+---------+-------+
Copied!
To find who set the current configuration values, we can query the dolt_blame_app_config table:
1
> select * from dolt_blame_app_config;
2
+-----+----------------------------------+-----------------------------------+-----------------+-------------------+-------------------------------+
3
| id | commit | commit_date | committer | email | message |
4
+-----+----------------------------------+-----------------------------------+-----------------+-------------------+-------------------------------+
5
| 1 | gift4cdu4m0daedgppu8m3uiuh8sovc8 | 2022-02-22 20:05:08.881 +0000 UTC | Thomas Foolery, | [email protected] | updating display config value |
6
| 2 | 30c2qqv3u6mvfsd11g0t1ejk0j974f71 | 2022-02-22 20:05:09.14 +0000 UTC | Harry Wombat, | [email protected] | switching to file encryption |
7
| 3 | s15jrjbtg1mq5sfmekpgdomijcr4jsq0 | 2022-02-22 20:05:09.265 +0000 UTC | Johnny Moolah, | [email protected] | adding new config for format |
8
| 4 | s15jrjbtg1mq5sfmekpgdomijcr4jsq0 | 2022-02-22 20:05:09.265 +0000 UTC | Johnny Moolah, | [email protected] | adding new config for format |
9
+-----+----------------------------------+-----------------------------------+-----------------+-------------------+-------------------------------+
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_commit_diff_$TABLENAME

For every user table named $TABLENAME, there is a read-only system table named dolt_commit_diff_$TABLENAME that can be queried to see a diff of the data in the specified table between any two commits in the database. For example, you can use this system table to view the diff between two commits on different branches. The schema of the returned data from this system table is based on the schema of the underlying user table at the currently checked out branch.
You must provide from_commit and to_commit in all queries to this system table in order to specify the to and from points for the diff of your table data. Each returned row describes how a row in the underlying user table has changed from the from_commit ref to the to_commit ref by showing the old and new values.
dolt_commit_diff_$TABLENAME is the analogue of the dolt diff CLI command. It represents the two-dot diff between the two commits provided. The dolt_diff_$TABLENAME system table also exposes diff information, but instead of a two-way diff, it returns a log of individual diffs between all adjacent commits in the history of the current branch. In other words, if a row was changed in 10 separate commits, dolt_diff_$TABLENAME will show 10 separate rows – one for each individual delta. In contrast, dolt_commit_diff_$TABLENAME would show a single row that combines all the individual commit deltas into one diff.
The DOLT_DIFF() table function is an alternative to the dolt_commit_diff_$tablename system table for cases where a table's schema has changed between the to and from commits. Consider the DOLT_DIFF() table function if you need to see the schema from each of those commits, instead of using the schema from the currently checked out branch.

Schema

1
+------------------+----------+
2
| field | type |
3
+------------------+----------+
4
| from_commit | TEXT |
5
| from_commit_date | DATETIME |
6
| to_commit | TEXT |
7
| to_commit_date | DATETIME |
8
| diff_type | TEXT |
9
| other cols | |
10
+------------------+----------+
Copied!
The remaining columns are dependent on the schema of the user table at the currently checked out branch. For every column X in your table at the currently checked out branch, there are columns in the result set named from_X and to_X with the same type as X in the current schema. The from_commit and to_commit parameters must both be specified in the query, or an error is returned.

Example Schema

Consider a simple example with a table that has two columns:
1
+--------------+
2
| field | type |
3
+--------------+
4
| pk | int |
5
| val | int |
6
+--------------+
Copied!
Based on the table's schema above, the schema 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

Now consider the following branch structure:
1
A---B---C feature
2
/
3
D---E---F---G main
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.
1
SELECT * from dolt_commit_diff_$TABLENAME where to_commit=HASHOF('feature') and from_commit = HASHOF('main');
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, without including the changes from F and G on main.
1
SELECT * FROM dolt_commit_diff_$TABLENAME WHERE to_commit=HASHOF('feature') and from_commit=dolt_merge_base('main', 'feature');
Copied!
The dolt_merge_base function computes the closest ancestor E between main 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_commits

The dolt_commits system table shows ALL commits in a Dolt database.
This is similar, but different from the dolt_log system table and the dolt log CLI command. dolt log shows you commit history for all commit ancestors reachable from the current HEAD of the checked out branch, whereas dolt_commits shows all commits from the entire database, no matter which branch is checked out.

Schema

1
> describe dolt_commits;
2
+-------------+----------+------+-----+---------+-------+
3
| Field | Type | Null | Key | Default | Extra |
4
+-------------+----------+------+-----+---------+-------+
5
| commit_hash | text | NO | PRI | | |
6
| committer | text | NO | | | |
7
| email | text | NO | | | |
8
| date | datetime | NO | | | |
9
| message | text | NO | | | |
10
+-------------+----------+------+-----+---------+-------+
Copied!

Example Query

Using the dolthub/SHAQ database from DoltHub, we can query for the five most recent commits before November 1st, 2021, across all commits in the database (regardless of what is checked out to HEAD) with this query:
1
SELECT *
2
FROM dolt_commits
3
WHERE date < "2021-11-01"
4
ORDER BY date DESC
5
LIMIT 5;
Copied!
1
+----------------------------------+-----------+--------------------+-----------------------------------+--------------------------------------------------------+
2
| commit_hash | committer | email | date | message |
3
+----------------------------------+-----------+--------------------+-----------------------------------+--------------------------------------------------------+
4
| 57cbn09m8egip6anq5c8s94uhhvaifkp | bpf120 | [email protected] | 2021-10-22 11:13:32.125 -0700 PDT | Merge pull request #43 from brian_add_all_team_seasons |
5
| nqpgo65t5rcq2gkcvnfigqpsabc42qln | bpf120 | [email protected] | 2021-10-22 11:13:17.919 -0700 PDT | Merge pull request #41 from brian |
6
| vto66re76lvfri7ls0ndu3m9fg47s4li | bpf120 | [email protected] | 2021-10-22 08:28:20.748 -0700 PDT | Added all teams for all seasons |
7
| akiasoe4jp68gq3k4fbhdni6ti0lntqk | bpf120 | [email protected] | 2021-10-22 04:19:07.037 -0700 PDT | Adding BAA to league tables |
8
| ptau7oesshub36075l12bqp7cejqu64j | bpf120 | [email protected] | 2021-10-22 04:09:07.604 -0700 PDT | Adding ABA as a league |
9
+----------------------------------+-----------+--------------------+-----------------------------------+--------------------------------------------------------+
Copied!

dolt_diff

The dolt_diff system table shows which tables in the current database were changed in each commit reachable from the active branch's HEAD. When multiple tables are changed in a single commit, there is one row in the dolt_diff system table for each table, all with the same commit hash. Any staged or unstaged changes in the working set are included with the value WORKING for their commit_hash. After identifying the tables that changed in a commit, the dolt_diff_$TABLENAME system tables can be used to determine the data that changed in each table.

Schema

The DOLT_DIFF system table has the following columns
1
+-------------+----------+
2
| field | Type |
3
+-------------+----------+
4
| commit_hash | text |
5
| table_name | text |
6
| committer | text |
7
| email | text |
8
| date | datetime |
9
| message | text |
10
+-------------+----------+
Copied!

Query Details

dolt_diff displays the changes from the current branch HEAD, including any working set changes. If a commit did not make any changes to tables (e.g. an empty commit), it is not included in the dolt_diff results.

Example Query

Taking the dolthub/nba-players database from DoltHub as our example, the following query uses the dolt_diff system table to find all commits, and the tables they changed, from the month of October, 2020.
1
SELECT commit_hash, table_name
2
FROM dolt_diff
3
WHERE date BETWEEN "2020-10-01" AND "2020-10-31";
Copied!
1
+----------------------------------+------------------------------+
2
| commit_hash | table_name |
3
+----------------------------------+------------------------------+
4
| rla1p8emnp91urj3uant52msrskouqil | draft_history |
5
| 1gtq675ira4phn3ib05ri0qksdp13ut3 | career_totals_post_season |
6
| 1gtq675ira4phn3ib05ri0qksdp13ut3 | career_totals_regular_season |
7
| 1gtq675ira4phn3ib05ri0qksdp13ut3 | rankings_post_season |
8
| 1gtq675ira4phn3ib05ri0qksdp13ut3 | rankings_regular_season |
9
| 1gtq675ira4phn3ib05ri0qksdp13ut3 | season_totals_allstar |
10
| 1gtq675ira4phn3ib05ri0qksdp13ut3 | season_totals_post_season |
11
| 1gtq675ira4phn3ib05ri0qksdp13ut3 | season_totals_regular_season |
12
| jbk2ckroo4hhqovrcpiv7c615dlsf3ut | draft_history |
13
| pu60cdppae7rumf1lm06j5ngkijp7i8f | players |
14
+----------------------------------+------------------------------+
Copied!
From these results, we can see there were four commits to this database in October, 2020. Commits rla1p8em and jbk2ckro only changed the draft_history table, commit pu60cdpp changed the players table, and commit 1gtq675i made changes to seven tables. To dig deeper into these changes, we can query the dolt_diff_$TABLE system tables specific to each of the changed tables, like this:
1
SELECT count(*) as total_rows_changed
2
FROM dolt_diff_players
3
WHERE to_commit='pu60cdppae7rumf1lm06j5ngkijp7i8f';
Copied!
1
+--------------------+
2
| total_rows_changed |
3
+--------------------+
4
| 4501 |
5
+--------------------+
Copied!

dolt_diff_$TABLENAME

For every user table named $TABLENAME, there is a read-only system table named dolt_diff_$TABLENAME that returns a list of diffs showing how rows have changed over time on the current branch. Each row in the result set represents a row that has changed between two adjacent commits on the current branch – if a row has been updated in 10 commits, then 10 individual rows are returned, showing each of the 10 individual updates.
Compared to the dolt_commit_diff_$TABLENAME system table, the dolt_diff_$TABLENAME system table focuses on how a particular row has evolved over time in the current branch's history. The major differences are that dolt_commit_diff_$TABLENAME requires specifying from_commit and to_commit, works on any commits in the database (not just the current branch), and returns a single combined diff for all changes to a row between those two commits. In the example above where a row is changed 10 times, dolt_commit_diff_$TABLENAME would only return a single row showing the diff, instead of the 10 individual deltas.

Schema

Every Dolt diff table will have the columns
1
+------------------+----------+
2
| field | type |
3
+------------------+----------+
4
| from_commit | TEXT |
5
| from_commit_date | DATETIME |
6
| to_commit | TEXT |
7
| to_commit_date | DATETIME |
8
| diff_type | TEXT |
9
| other cols | |
10
+------------------+----------+
Copied!
The remaining columns are dependent on the schema of the user table at the current branch. For every column X in your table at the current branch there will be columns in the result set named from_X and to_X with the same type as X.

Example Schema

For a table named states with the following schema:
1
+------------+--------+
2
| field | type |
3
+------------+--------+
4
| state | TEXT |
5
| population | BIGINT |
6
| area | BIGINT |
7
+-------------+-------+
Copied!
The schema for dolt_diff_states would be:
1
+------------------+----------+
2
| field | type |
3
+-----------------+-----------+
4
| from_state | TEXT |
5
| from_population | BIGINT |
6
| from_area | TEXT |
7
| from_commit | TEXT |
8
| from_commit_date | DATETIME |
9
| to_state | TEXT |
10
| to_population | BIGINT |
11
| to_area | TEXT |
12
| to_commit | TEXT |
13
| to_commit_date | DATETIME |
14
| diff_type | TEXT |
15
+------------------+----------+
Copied!

Query Details

A SELECT * query for a diff table will show you every change that has occurred to each row for every commit in this branch's history. Using to_commit or from_commit will 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. For example, to get the differences between the last commit and its 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 database 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_history_$TABLENAME

For every user table named $TABLENAME, there is a read-only system table named dolt_history_$TABLENAME that can be queried to find a row's value at every commit in the current branch's history.

Schema

Every Dolt history table contains columns for commit_hash, committer, and commit_date, plus every column from the user table's schema at the current checked out branch.
1
+-------------+----------+
2
| field | type |
3
+-------------+----------+
4
| commit_hash | TEXT |
5
| committer | TEXT |
6
| commit_date | DATETIME |
7
| other cols | |
8
+-------------+----------+
Copied!

Example Schema

Consider a table named states with the following schema:
1
+------------+--------+
2
| field | type |
3
+------------+--------+
4
| state | TEXT |
5
| capital | TEXT |
6
| population | BIGINT |
7
| area | BIGINT |
8
| counties | BIGINT |
9
+------------+--------+
Copied!
The schema for dolt_history_states would be:
1
+-------------+----------+
2
| field | type |
3
+-------------+----------+
4
| state | TEXT |
5
| capital | TEXT |
6
| population | BIGINT |
7
| area | BIGINT |
8
| counties | BIGINT |
9
| commit_hash | TEXT |
10
| committer | TEXT |
11
| commit_date | DATETIME |
12
+-------------+----------+
Copied!

Example Query

Assume a database with the states table above and the following commit graph:
1
B---E feature
2
/
3
A---C---D main
Copied!
When the main branch is checked out, the following query returns the results below, showing the state of the Virginia row at every ancestor commit reachable from our current branch.
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 | 877683 | Richmond | 42774 | 75 | HASHOF(D) | billybob | 1810-01-01 00:00:00.0 +0000 UTC |
5
| Virginia | 807557 | Richmond | 42774 | 73 | HASHOF(C) | billybob | 1800-01-01 00:00:00.0 +0000 UTC |
6
| Virginia | 691937 | Williamsburg | 42774 | 68 | HASHOF(A) | billybob | 1778-01-09 00:00:00.0 +0000 UTC |
7
+----------+------------+--------------+--------+----------+-------------+-----------+---------------------------------+
8
9
# Note: in the real result set there would be actual commit hashes for each row.
Copied!

dolt_log

The dolt_log system table contains the commit log for all commits reachable from the current HEAD. This is the same data returned by the dolt log CLI command.

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

The following query shows the commits reachable from the current checked out head and created by user bheni since April, 2019:
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_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_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_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.