github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/doltcore/sqle/enginetest/dolt_queries_diff.go (about)

     1  // Copyright 2022-2024 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package enginetest
    16  
    17  import (
    18  	"github.com/dolthub/go-mysql-server/enginetest/queries"
    19  	"github.com/dolthub/go-mysql-server/sql"
    20  	gmstypes "github.com/dolthub/go-mysql-server/sql/types"
    21  
    22  	"github.com/dolthub/dolt/go/libraries/doltcore/sqle"
    23  	"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
    24  )
    25  
    26  var DiffSystemTableScriptTests = []queries.ScriptTest{
    27  	{
    28  		Name: "base case: added rows",
    29  		SetUpScript: []string{
    30  			"create table t (pk int primary key, c1 int, c2 int);",
    31  			"call dolt_add('.')",
    32  			"insert into t values (1, 2, 3), (4, 5, 6);",
    33  			"set @Commit1 = '';",
    34  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
    35  		},
    36  		Assertions: []queries.ScriptTestAssertion{
    37  			{
    38  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF_t;",
    39  				Expected: []sql.Row{{2}},
    40  			},
    41  			{
    42  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit1 ORDER BY to_pk, to_c2, to_c2, from_pk, from_c1, from_c2, diff_type;",
    43  				Expected: []sql.Row{
    44  					{1, 2, 3, nil, nil, nil, "added"},
    45  					{4, 5, 6, nil, nil, nil, "added"},
    46  				},
    47  			},
    48  		},
    49  	},
    50  	{
    51  		Name: "base case: modified rows",
    52  		SetUpScript: []string{
    53  			"create table t (pk int primary key, c1 int, c2 int);",
    54  			"call dolt_add('.')",
    55  			"insert into t values (1, 2, 3), (4, 5, 6);",
    56  			"set @Commit1 = '';",
    57  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
    58  
    59  			"update t set c2=0 where pk=1",
    60  			"set @Commit2 = '';",
    61  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'modifying row');",
    62  		},
    63  		Assertions: []queries.ScriptTestAssertion{
    64  			{
    65  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF_t;",
    66  				Expected: []sql.Row{{3}},
    67  			},
    68  			{
    69  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit2 ORDER BY to_pk, to_c2, to_c2, from_pk, from_c1, from_c2, diff_type;",
    70  				Expected: []sql.Row{
    71  					{1, 2, 0, 1, 2, 3, "modified"},
    72  				},
    73  			},
    74  		},
    75  	},
    76  	{
    77  		Name: "base case: deleted row",
    78  		SetUpScript: []string{
    79  			"create table t (pk int primary key, c1 int, c2 int);",
    80  			"call dolt_add('.')",
    81  			"insert into t values (1, 2, 3), (4, 5, 6);",
    82  			"set @Commit1 = '';",
    83  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
    84  
    85  			"delete from t where pk=1",
    86  			"set @Commit2 = '';",
    87  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'modifying row');",
    88  		},
    89  		Assertions: []queries.ScriptTestAssertion{
    90  			{
    91  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF_t;",
    92  				Expected: []sql.Row{{3}},
    93  			},
    94  			{
    95  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit2 ORDER BY to_pk;",
    96  				Expected: []sql.Row{
    97  					{nil, nil, nil, 1, 2, 3, "removed"},
    98  				},
    99  			},
   100  		},
   101  	},
   102  	{
   103  		// In this case, we do not expect to see the old/dropped table included in the dolt_diff_table output
   104  		Name: "table drop and recreate with overlapping schema",
   105  		SetUpScript: []string{
   106  			"create table t (pk int primary key, c int);",
   107  			"call dolt_add('.')",
   108  			"insert into t values (1, 2), (3, 4);",
   109  			"set @Commit1 = '';",
   110  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
   111  
   112  			"drop table t;",
   113  			"set @Commit2 = '';",
   114  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping table t');",
   115  
   116  			"create table t (pk int primary key, c int);",
   117  			"call dolt_add('.')",
   118  			"insert into t values (100, 200), (300, 400);",
   119  			"set @Commit3 = '';",
   120  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'recreating table t');",
   121  		},
   122  		Assertions: []queries.ScriptTestAssertion{
   123  			{
   124  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF_t",
   125  				Expected: []sql.Row{{2}},
   126  			},
   127  			{
   128  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit3 ORDER BY to_pk;",
   129  				Expected: []sql.Row{
   130  					{100, 200, nil, nil, "added"},
   131  					{300, 400, nil, nil, "added"},
   132  				},
   133  			},
   134  		},
   135  	},
   136  	{
   137  		// When a column is dropped we should see the column's value set to null in that commit
   138  		Name: "column drop",
   139  		SetUpScript: []string{
   140  			"create table t (pk int primary key, c1 int, c2 int);",
   141  			"call dolt_add('.')",
   142  			"insert into t values (1, 2, 3), (4, 5, 6);",
   143  			"set @Commit1 = '';",
   144  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
   145  
   146  			"alter table t drop column c1;",
   147  			"set @Commit2 = '';",
   148  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');",
   149  		},
   150  		Assertions: []queries.ScriptTestAssertion{
   151  			{
   152  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF_t;",
   153  				Expected: []sql.Row{{4}},
   154  			},
   155  			{
   156  				Query: "SELECT to_pk, to_c2, from_pk, from_c2 FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit1 ORDER BY to_pk;",
   157  				Expected: []sql.Row{
   158  					{1, 3, nil, nil},
   159  					{4, 6, nil, nil},
   160  				},
   161  			},
   162  			{
   163  				Query: "SELECT to_pk, to_c2, from_pk, from_c2 FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit2 ORDER BY to_pk;",
   164  				Expected: []sql.Row{
   165  					{1, 3, 1, 3},
   166  					{4, 6, 4, 6},
   167  				},
   168  			},
   169  		},
   170  	},
   171  	{
   172  		// When a column is dropped and recreated with the same type, we expect it to be included in dolt_diff output
   173  		Name: "column drop and recreate with same type",
   174  		SetUpScript: []string{
   175  			"create table t (pk int primary key, c int);",
   176  			"call dolt_add('.')",
   177  			"insert into t values (1, 2), (3, 4);",
   178  			"set @Commit1 = '';",
   179  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
   180  
   181  			"alter table t drop column c;",
   182  			"set @Commit2 = '';",
   183  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');",
   184  
   185  			"alter table t add column c int;",
   186  			"insert into t values (100, 101);",
   187  			"set @Commit3 = '';",
   188  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'inserting into t');",
   189  		},
   190  		Assertions: []queries.ScriptTestAssertion{
   191  			{
   192  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF_t;",
   193  				Expected: []sql.Row{{5}},
   194  			},
   195  			{
   196  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit1 ORDER BY to_pk;",
   197  				Expected: []sql.Row{
   198  					{1, 2, nil, nil, "added"},
   199  					{3, 4, nil, nil, "added"},
   200  				},
   201  			},
   202  			{
   203  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit2 ORDER BY to_pk;",
   204  				Expected: []sql.Row{
   205  					{1, nil, 1, 2, "modified"},
   206  					{3, nil, 3, 4, "modified"},
   207  				},
   208  			},
   209  			{
   210  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit3 ORDER BY to_pk;",
   211  				Expected: []sql.Row{
   212  					{100, 101, nil, nil, "added"},
   213  				},
   214  			},
   215  		},
   216  	},
   217  	{
   218  		// When a column is dropped and then another column with the same type is renamed to that name, we expect it to be included in dolt_diff output
   219  		Name: "column drop, then rename column with same type to same name",
   220  		SetUpScript: []string{
   221  			"create table t (pk int primary key, c1 int, c2 int);",
   222  			"call dolt_add('.')",
   223  			"insert into t values (1, 2, 3), (4, 5, 6);",
   224  			"set @Commit1 = '';",
   225  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
   226  
   227  			"alter table t drop column c1;",
   228  			"set @Commit2 = '';",
   229  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c1');",
   230  
   231  			"alter table t rename column c2 to c1;",
   232  			"insert into t values (100, 101);",
   233  			"set @Commit3 = '';",
   234  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'inserting into t');",
   235  		},
   236  		Assertions: []queries.ScriptTestAssertion{
   237  			{
   238  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF_t;",
   239  				Expected: []sql.Row{{5}},
   240  			},
   241  			{
   242  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit1 ORDER BY to_pk;",
   243  				Expected: []sql.Row{
   244  					{1, 2, nil, nil, "added"},
   245  					{4, 5, nil, nil, "added"},
   246  				},
   247  			},
   248  			{
   249  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit2 ORDER BY to_pk;",
   250  				Expected: []sql.Row{
   251  					{1, nil, 1, 2, "modified"},
   252  					{4, nil, 4, 5, "modified"},
   253  				},
   254  			},
   255  			{
   256  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit3 ORDER BY to_pk;",
   257  				Expected: []sql.Row{
   258  					{100, 101, nil, nil, "added"},
   259  					// TODO: It's more correct to also return the following rows.
   260  					//{1, 3, 1, nil, "modified"},
   261  					//{4, 6, 4, nil, "modified"}
   262  
   263  					// To explain why, let's inspect table t at each of the commits:
   264  					//
   265  					//     @Commit1          @Commit2         @Commit3
   266  					// +----+----+----+     +----+----+     +-----+-----+
   267  					// | pk | c1 | c2 |     | pk | c2 |     | pk  | c1  |
   268  					// +----+----+----+     +----+----+     +-----+-----+
   269  					// | 1  | 2  | 3  |     | 1  | 3  |     | 1   | 3   |
   270  					// | 4  | 5  | 6  |     | 4  | 6  |     | 4   | 6   |
   271  					// +----+----+----+     +----+----+     | 100 | 101 |
   272  					//                                      +-----+-----+
   273  					//
   274  					// If you were to interpret each table using the schema at
   275  					// @Commit3, (pk, c1), you would see the following:
   276  					//
   277  					//   @Commit1            @Commit2         @Commit3
   278  					// +----+----+         +----+------+     +-----+-----+
   279  					// | pk | c1 |         | pk | c1   |     | pk  | c1  |
   280  					// +----+----+         +----+------+     +-----+-----+
   281  					// | 1  | 2  |         | 1  | NULL |     | 1   | 3   |
   282  					// | 4  | 5  |         | 4  | NULL |     | 4   | 6   |
   283  					// +----+----+         +----+------+     | 100 | 101 |
   284  					//                                       +-----+-----+
   285  					//
   286  					// The corresponding diffs for the interpreted tables:
   287  					//
   288  					// Diff between init and @Commit1:
   289  					// + (1, 2)
   290  					// + (4, 5)
   291  					//
   292  					// Diff between @Commit1 and @Commit2:
   293  					// ~ (1, NULL)
   294  					// ~ (4, NULL)
   295  					//
   296  					// Diff between @Commit2 and @Commit3:
   297  					// ~ (1, 3) <- currently not outputted
   298  					// ~ (4, 6) <- currently not outputted
   299  					// + (100, 101)
   300  					//
   301  					// The missing rows are not produced by diff since the
   302  					// underlying value of the prolly trees are not modified during a column rename.
   303  				},
   304  			},
   305  		},
   306  	},
   307  	{
   308  		// When a column is dropped and recreated with a different type, we expect only the new column
   309  		// to be included in dolt_diff output, with previous values coerced (with any warnings reported) to the new type
   310  		Name: "column drop and recreate with different type that can be coerced (int -> string)",
   311  		SetUpScript: []string{
   312  			"create table t (pk int primary key, c int);",
   313  			"call dolt_add('.')",
   314  			"insert into t values (1, 2), (3, 4);",
   315  			"set @Commit1 = '';",
   316  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
   317  
   318  			"alter table t drop column c;",
   319  			"set @Commit2 = '';",
   320  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');",
   321  
   322  			"alter table t add column c varchar(20);",
   323  			"insert into t values (100, '101');",
   324  			"set @Commit3 = '';",
   325  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 're-adding column c');",
   326  		},
   327  		Assertions: []queries.ScriptTestAssertion{
   328  			{
   329  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF_t;",
   330  				Expected: []sql.Row{{5}},
   331  			},
   332  			{
   333  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit1 ORDER BY to_pk;",
   334  				Expected: []sql.Row{
   335  					{1, "2", nil, nil, "added"},
   336  					{3, "4", nil, nil, "added"},
   337  				},
   338  			},
   339  			{
   340  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit2 ORDER BY to_pk;",
   341  				Expected: []sql.Row{
   342  					{1, nil, 1, "2", "modified"},
   343  					{3, nil, 3, "4", "modified"},
   344  				},
   345  			},
   346  			{
   347  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit3 ORDER BY to_pk;",
   348  				Expected: []sql.Row{
   349  					{100, "101", nil, nil, "added"},
   350  				},
   351  			},
   352  		},
   353  	},
   354  	{
   355  		Name: "column drop and recreate with different type that can NOT be coerced (string -> int)",
   356  		SetUpScript: []string{
   357  			"create table t (pk int primary key, c varchar(20));",
   358  			"call dolt_add('.')",
   359  			"insert into t values (1, 'two'), (3, 'four');",
   360  			"set @Commit1 = '';",
   361  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
   362  
   363  			"alter table t drop column c;",
   364  			"set @Commit2 = '';",
   365  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');",
   366  
   367  			"alter table t add column c int;",
   368  			"insert into t values (100, 101);",
   369  			"set @Commit3 = '';",
   370  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 're-adding column c');",
   371  		},
   372  		Assertions: []queries.ScriptTestAssertion{
   373  			{
   374  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF_t;",
   375  				Expected: []sql.Row{{5}},
   376  			},
   377  			{
   378  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit1 ORDER BY to_pk;",
   379  				Expected: []sql.Row{
   380  					{1, nil, nil, nil, "added"},
   381  					{3, nil, nil, nil, "added"},
   382  				},
   383  			},
   384  			{
   385  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit2 ORDER BY to_pk;",
   386  				Expected: []sql.Row{
   387  					{1, nil, 1, nil, "modified"},
   388  					{3, nil, 3, nil, "modified"},
   389  				},
   390  			},
   391  			{
   392  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit3 ORDER BY to_pk;",
   393  				Expected: []sql.Row{
   394  					{100, 101, nil, nil, "added"},
   395  				},
   396  			},
   397  			{
   398  				Query:                           "select * from dolt_diff_t;",
   399  				ExpectedWarning:                 1105,
   400  				ExpectedWarningsCount:           4,
   401  				ExpectedWarningMessageSubstring: "unable to coerce value from field",
   402  				SkipResultsCheck:                true,
   403  			},
   404  		},
   405  	},
   406  	{
   407  		// https://github.com/dolthub/dolt/issues/6391
   408  		Name: "columns modified to narrower types",
   409  		SetUpScript: []string{
   410  			"create table t (pk int primary key, col1 varchar(20), col2 int);",
   411  			"call dolt_commit('-Am', 'new table t');",
   412  			"insert into t values (1, '123456789012345', 420);",
   413  			"call dolt_commit('-am', 'inserting data');",
   414  			"update t set col1='1234567890', col2=13;",
   415  			"alter table t modify column col1 varchar(10);",
   416  			"alter table t modify column col2 tinyint;",
   417  			"call dolt_commit('-am', 'narrowing types');",
   418  		},
   419  		Assertions: []queries.ScriptTestAssertion{
   420  			{
   421  				Query: "select to_pk, to_col1, to_col2, to_commit, from_pk, from_col1, from_col2, from_commit, diff_type from dolt_diff_t order by diff_type ASC;",
   422  				Expected: []sql.Row{
   423  					{1, nil, nil, doltCommit, nil, nil, nil, doltCommit, "added"},
   424  					{1, "1234567890", 13, doltCommit, 1, nil, nil, doltCommit, "modified"},
   425  				},
   426  				ExpectedWarningsCount: 4,
   427  			},
   428  			{
   429  				Query: "SHOW WARNINGS;",
   430  				Expected: []sql.Row{
   431  					{"Warning", 1292, "Truncated tinyint value: 420"},
   432  					{"Warning", 1292, "Truncated tinyint value: 420"},
   433  					{"Warning", 1292, "Truncated varchar(10) value: 123456789012345"},
   434  					{"Warning", 1292, "Truncated varchar(10) value: 123456789012345"},
   435  				},
   436  			},
   437  		},
   438  	},
   439  	{
   440  		Name: "multiple column renames",
   441  		SetUpScript: []string{
   442  			"create table t (pk int primary key, c1 int);",
   443  			"call dolt_add('.')",
   444  			"insert into t values (1, 2);",
   445  			"set @Commit1 = '';",
   446  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
   447  
   448  			"alter table t rename column c1 to c2;",
   449  			"insert into t values (3, 4);",
   450  			"set @Commit2 = '';",
   451  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'renaming c1 to c2');",
   452  
   453  			"alter table t drop column c2;",
   454  			"set @Commit3 = '';",
   455  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'dropping column c2');",
   456  
   457  			"alter table t add column c2 int;",
   458  			"insert into t values (100, '101');",
   459  			"set @Commit4 = '';",
   460  			"CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'recreating column c2');",
   461  		},
   462  		Assertions: []queries.ScriptTestAssertion{
   463  			{
   464  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF_t;",
   465  				Expected: []sql.Row{{5}},
   466  			},
   467  			{
   468  				Query: "SELECT to_pk, to_c2, from_pk, from_c2, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit1 ORDER BY to_pk;",
   469  				Expected: []sql.Row{
   470  					{1, nil, nil, nil, "added"},
   471  				},
   472  			},
   473  			{
   474  				Query: "SELECT to_pk, to_c2, from_pk, from_c2, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit2 ORDER BY to_pk;",
   475  				Expected: []sql.Row{
   476  					{3, 4, nil, nil, "added"},
   477  				},
   478  			},
   479  			{
   480  				Query: "SELECT to_pk, to_c2, from_pk, from_c2, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit3 ORDER BY to_pk;",
   481  				Expected: []sql.Row{
   482  					{1, nil, 1, 2, "modified"},
   483  					{3, nil, 3, 4, "modified"},
   484  				},
   485  			},
   486  			{
   487  				Query: "SELECT to_pk, to_c2, from_pk, from_c2, diff_type FROM DOLT_DIFF_t WHERE TO_COMMIT=@Commit4 ORDER BY to_pk;",
   488  				Expected: []sql.Row{
   489  					{100, 101, nil, nil, "added"},
   490  				},
   491  			},
   492  		},
   493  	},
   494  	{
   495  		Name: "primary key change",
   496  		SetUpScript: []string{
   497  			"create table t (pk int primary key, c1 int);",
   498  			"call dolt_add('.')",
   499  			"insert into t values (1, 2), (3, 4);",
   500  			"set @Commit1 = '';",
   501  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
   502  
   503  			"alter table t drop primary key;",
   504  			"insert into t values (5, 6);",
   505  			"set @Commit2 = '';",
   506  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping primary key');",
   507  
   508  			"alter table t add primary key (c1);",
   509  			"set @Commit3 = '';",
   510  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'adding primary key');",
   511  
   512  			"insert into t values (7, 8);",
   513  			"set @Commit4 = '';",
   514  			"CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'adding more data');",
   515  		},
   516  		Assertions: []queries.ScriptTestAssertion{
   517  			{
   518  				Query:                           "select * from dolt_diff_t;",
   519  				ExpectedWarning:                 1105,
   520  				ExpectedWarningsCount:           1,
   521  				ExpectedWarningMessageSubstring: "cannot render full diff between commits",
   522  				SkipResultsCheck:                true,
   523  			},
   524  			{
   525  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF_t;",
   526  				Expected: []sql.Row{{1}},
   527  			},
   528  			{
   529  				Query:    "SELECT to_pk, to_c1, from_pk, from_c1, diff_type FROM DOLT_DIFF_t where to_commit=@Commit4;",
   530  				Expected: []sql.Row{{7, 8, nil, nil, "added"}},
   531  			},
   532  		},
   533  	},
   534  	{
   535  		Name: "table with commit column should maintain its data in diff",
   536  		SetUpScript: []string{
   537  			"CREATE TABLE t (pk int PRIMARY KEY, commit_msg varchar(20));",
   538  			"CALL DOLT_ADD('.')",
   539  			"CALL dolt_commit('-am', 'creating table t');",
   540  			"INSERT INTO t VALUES (1, 'hi');",
   541  			"CALL dolt_commit('-am', 'insert data');",
   542  		},
   543  		Assertions: []queries.ScriptTestAssertion{
   544  			{
   545  				Query:    "SELECT to_pk, char_length(to_commit), from_pk, char_length(from_commit), diff_type from dolt_diff_t;",
   546  				Expected: []sql.Row{{1, 32, nil, 32, "added"}},
   547  			},
   548  		},
   549  	},
   550  	{
   551  		Name: "selecting to_pk columns",
   552  		SetUpScript: []string{
   553  			"create table t (pk int primary key, c1 int, c2 int);",
   554  			"call dolt_add('.')",
   555  			"insert into t values (1, 2, 3), (4, 5, 6);",
   556  			"set @Commit1 = '';",
   557  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'first commit');",
   558  			"insert into t values (7, 8, 9);",
   559  			"set @Commit2 = '';",
   560  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'second commit');",
   561  			"update t set c1 = 0 where pk > 5;",
   562  			"set @Commit3 = '';",
   563  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'third commit');",
   564  		},
   565  		Assertions: []queries.ScriptTestAssertion{
   566  			{
   567  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF_t;",
   568  				Expected: []sql.Row{{4}},
   569  			},
   570  			{
   571  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type FROM DOLT_DIFF_t WHERE to_pk = 1 ORDER BY to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type;",
   572  				Expected: []sql.Row{
   573  					{1, 2, 3, nil, nil, nil, "added"},
   574  				},
   575  			},
   576  			{
   577  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type FROM DOLT_DIFF_t WHERE to_pk > 1 ORDER BY to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type;",
   578  				Expected: []sql.Row{
   579  					{4, 5, 6, nil, nil, nil, "added"},
   580  					{7, 0, 9, 7, 8, 9, "modified"},
   581  					{7, 8, 9, nil, nil, nil, "added"},
   582  				},
   583  			},
   584  		},
   585  	},
   586  	{
   587  		Name: "selecting to_pk1 and to_pk2 columns",
   588  		SetUpScript: []string{
   589  			"create table t (pk1 int, pk2 int, c1 int, primary key (pk1, pk2));",
   590  			"call dolt_add('.')",
   591  			"insert into t values (1, 2, 3), (4, 5, 6);",
   592  			"set @Commit1 = '';",
   593  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'first commit');",
   594  			"insert into t values (7, 8, 9);",
   595  			"set @Commit2 = '';",
   596  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'second commit');",
   597  			"update t set c1 = 0 where pk1 > 5;",
   598  			"set @Commit3 = '';",
   599  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'third commit');",
   600  		},
   601  		Assertions: []queries.ScriptTestAssertion{
   602  			{
   603  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF_t;",
   604  				Expected: []sql.Row{{4}},
   605  			},
   606  			{
   607  				Query: "SELECT to_pk1, to_pk2, to_c1, from_pk1, from_pk2, from_c1, diff_type FROM DOLT_DIFF_t WHERE to_pk1 = 1 ORDER BY to_pk1, to_pk2, to_c1, from_pk1, from_pk2, from_c1, diff_type;",
   608  				Expected: []sql.Row{
   609  					{1, 2, 3, nil, nil, nil, "added"},
   610  				},
   611  			},
   612  			{
   613  				Query: "SELECT to_pk1, to_pk2, to_c1, from_pk1, from_pk2, from_c1, diff_type FROM DOLT_DIFF_t WHERE to_pk1 = 1 and to_pk2 = 2 ORDER BY to_pk1, to_pk2, to_c1, from_pk1, from_pk2, from_c1, diff_type;",
   614  				Expected: []sql.Row{
   615  					{1, 2, 3, nil, nil, nil, "added"},
   616  				},
   617  			},
   618  			{
   619  				Query: "SELECT to_pk1, to_pk2, to_c1, from_pk1, from_pk2, from_c1, diff_type FROM DOLT_DIFF_t WHERE to_pk1 > 1 and to_pk2 < 10 ORDER BY to_pk1, to_pk2, to_c1, from_pk1, from_pk2, from_c1, diff_type;",
   620  				Expected: []sql.Row{
   621  					{4, 5, 6, nil, nil, nil, "added"},
   622  					{7, 8, 0, 7, 8, 9, "modified"},
   623  					{7, 8, 9, nil, nil, nil, "added"},
   624  				},
   625  			},
   626  		},
   627  	},
   628  	{
   629  		Name: "Diff table shows diffs across primary key renames",
   630  		SetUpScript: []string{
   631  			"CREATE TABLE t (pk1 int PRIMARY KEY);",
   632  			"INSERT INTO t values (1);",
   633  			"CREATE table t2 (pk1a int, pk1b int, PRIMARY KEY (pk1a, pk1b));",
   634  			"CALL DOLT_ADD('.')",
   635  			"INSERT INTO t2 values (2, 2);",
   636  			"CALL DOLT_COMMIT('-am', 'initial');",
   637  
   638  			"ALTER TABLE t RENAME COLUMN pk1 to pk2",
   639  			"ALTER TABLE t2 RENAME COLUMN pk1a to pk2a",
   640  			"ALTER TABLE t2 RENAME COLUMN pk1b to pk2b",
   641  			"CALL DOLT_COMMIT('-am', 'rename primary key')",
   642  		},
   643  		Assertions: []queries.ScriptTestAssertion{
   644  			{
   645  				Query:    "SELECT from_pk2, to_pk2, diff_type from dolt_diff_t;",
   646  				Expected: []sql.Row{{nil, 1, "added"}},
   647  			},
   648  			{
   649  				Query:    "SELECT from_pk2a, from_pk2b, to_pk2a, to_pk2b, diff_type from dolt_diff_t2;",
   650  				Expected: []sql.Row{{nil, nil, 2, 2, "added"}},
   651  			},
   652  		},
   653  	},
   654  	{
   655  		Name: "add multiple columns, then set and unset a value. Should not show a diff",
   656  		SetUpScript: []string{
   657  			"CREATE table t (pk int primary key);",
   658  			"Insert into t values (1);",
   659  			"alter table t add column col1 int;",
   660  			"alter table t add column col2 int;",
   661  			"CALL DOLT_ADD('.');",
   662  			"CALL DOLT_COMMIT('-am', 'setup');",
   663  			"UPDATE t set col1 = 1 where pk = 1;",
   664  			"UPDATE t set col1 = null where pk = 1;",
   665  			"CALL DOLT_COMMIT('--allow-empty', '-am', 'fix short tuple');",
   666  		},
   667  		Assertions: []queries.ScriptTestAssertion{
   668  			{
   669  				Query:    "SELECT to_pk, to_col1, from_pk, from_col1, diff_type from dolt_diff_t;",
   670  				Expected: []sql.Row{{1, nil, nil, nil, "added"}},
   671  			},
   672  		},
   673  	},
   674  }
   675  
   676  var Dolt1DiffSystemTableScripts = []queries.ScriptTest{
   677  	{
   678  		Name: "Diff table stops creating diff partitions when any primary key type has changed",
   679  		SetUpScript: []string{
   680  			"CREATE TABLE t (pk1 VARCHAR(100), pk2 VARCHAR(100), PRIMARY KEY (pk1, pk2));",
   681  			"CALL DOLT_ADD('.')",
   682  			"INSERT INTO t VALUES ('1', '1');",
   683  			"CALL DOLT_COMMIT('-am', 'setup');",
   684  
   685  			"ALTER TABLE t MODIFY COLUMN pk2 VARCHAR(101)",
   686  			"CALL DOLT_COMMIT('-am', 'modify column type');",
   687  
   688  			"INSERT INTO t VALUES ('2', '2');",
   689  			"CALL DOLT_COMMIT('-am', 'insert new row');",
   690  		},
   691  		Assertions: []queries.ScriptTestAssertion{
   692  			{
   693  				Query:    "SELECT to_pk1, to_pk2, from_pk1, from_pk2, diff_type from dolt_diff_t;",
   694  				Expected: []sql.Row{{"2", "2", nil, nil, "added"}},
   695  			},
   696  		},
   697  	},
   698  }
   699  
   700  var DiffTableFunctionScriptTests = []queries.ScriptTest{
   701  	{
   702  		Name: "invalid arguments",
   703  		SetUpScript: []string{
   704  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
   705  			"call dolt_add('.')",
   706  			"set @Commit1 = '';",
   707  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
   708  
   709  			"insert into t values(1, 'one', 'two'), (2, 'two', 'three');",
   710  			"set @Commit2 = '';",
   711  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');",
   712  		},
   713  		Assertions: []queries.ScriptTestAssertion{
   714  			{
   715  				Query:       "SELECT * from dolt_diff();",
   716  				ExpectedErr: sql.ErrInvalidArgumentNumber,
   717  			},
   718  			{
   719  				Query:       "SELECT * from dolt_diff('t');",
   720  				ExpectedErr: sql.ErrInvalidArgumentNumber,
   721  			},
   722  			{
   723  				Query:       "SELECT * from dolt_diff(@Commit1, 't');",
   724  				ExpectedErr: sql.ErrInvalidArgumentNumber,
   725  			},
   726  			{
   727  				Query:       "SELECT * from dolt_diff(@Commit1, @Commit2, 'extra', 't');",
   728  				ExpectedErr: sql.ErrInvalidArgumentNumber,
   729  			},
   730  			{
   731  				Query:       "SELECT * from dolt_diff(null, null, null);",
   732  				ExpectedErr: sql.ErrInvalidArgumentDetails,
   733  			},
   734  			{
   735  				Query:       "SELECT * from dolt_diff(@Commit1, @Commit2, 123);",
   736  				ExpectedErr: sql.ErrInvalidArgumentDetails,
   737  			},
   738  			{
   739  				Query:       "SELECT * from dolt_diff(123, @Commit2, 't');",
   740  				ExpectedErr: sql.ErrInvalidArgumentDetails,
   741  			},
   742  			{
   743  				Query:       "SELECT * from dolt_diff(@Commit1, 123, 't');",
   744  				ExpectedErr: sql.ErrInvalidArgumentDetails,
   745  			},
   746  			{
   747  				Query:       "SELECT * from dolt_diff(@Commit1, @Commit2, 'doesnotexist');",
   748  				ExpectedErr: sql.ErrTableNotFound,
   749  			},
   750  			{
   751  				Query:          "SELECT * from dolt_diff('fakefakefakefakefakefakefakefake', @Commit2, 't');",
   752  				ExpectedErrStr: "target commit not found",
   753  			},
   754  			{
   755  				Query:          "SELECT * from dolt_diff(@Commit1, 'fake-branch', 't');",
   756  				ExpectedErrStr: "branch not found: fake-branch",
   757  			},
   758  			{
   759  				Query:       "SELECT * from dolt_diff(@Commit1, concat('fake', '-', 'branch'), 't');",
   760  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
   761  			},
   762  			{
   763  				Query:       "SELECT * from dolt_diff(hashof('main'), @Commit2, 't');",
   764  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
   765  			},
   766  			{
   767  				Query:       "SELECT * from dolt_diff(hashof('main'), @Commit2, LOWER('T'));",
   768  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
   769  			},
   770  
   771  			{
   772  				Query:       "SELECT * from dolt_diff('main..main~');",
   773  				ExpectedErr: sql.ErrInvalidArgumentNumber,
   774  			},
   775  			{
   776  				Query:       "SELECT * from dolt_diff('main..main~', 'extra', 't');",
   777  				ExpectedErr: sql.ErrInvalidArgumentNumber,
   778  			},
   779  			{
   780  				Query:       "SELECT * from dolt_diff('main..main^', 123);",
   781  				ExpectedErr: sql.ErrInvalidArgumentDetails,
   782  			},
   783  			{
   784  				Query:       "SELECT * from dolt_diff('main..main~', 'doesnotexist');",
   785  				ExpectedErr: sql.ErrTableNotFound,
   786  			},
   787  			{
   788  				Query:          "SELECT * from dolt_diff('fakefakefakefakefakefakefakefake..main', 't');",
   789  				ExpectedErrStr: "target commit not found",
   790  			},
   791  			{
   792  				Query:          "SELECT * from dolt_diff('main..fakefakefakefakefakefakefakefake', 't');",
   793  				ExpectedErrStr: "target commit not found",
   794  			},
   795  			{
   796  				Query:          "SELECT * from dolt_diff('fakefakefakefakefakefakefakefake...main', 't');",
   797  				ExpectedErrStr: "target commit not found",
   798  			},
   799  			{
   800  				Query:          "SELECT * from dolt_diff('main...fakefakefakefakefakefakefakefake', 't');",
   801  				ExpectedErrStr: "target commit not found",
   802  			},
   803  			{
   804  				Query:       "SELECT * from dolt_diff('main..main~', LOWER('T'));",
   805  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
   806  			},
   807  		},
   808  	},
   809  	{
   810  		Name: "basic case",
   811  		SetUpScript: []string{
   812  			"set @Commit0 = HashOf('HEAD');",
   813  
   814  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
   815  			"call dolt_add('.')",
   816  			"set @Commit1 = '';",
   817  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
   818  
   819  			"insert into t values(1, 'one', 'two');",
   820  			"set @Commit2 = '';",
   821  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting into table t');",
   822  
   823  			"create table t2 (pk int primary key, c1 varchar(20), c2 varchar(20));",
   824  			"call dolt_add('.')",
   825  			"insert into t2 values(100, 'hundred', 'hundert');",
   826  			"set @Commit3 = '';",
   827  			"call dolt_commit_hash_out(@Commit3, '-am', 'inserting into table t2');",
   828  
   829  			"insert into t values(2, 'two', 'three'), (3, 'three', 'four');",
   830  			"update t set c1='uno', c2='dos' where pk=1;",
   831  			"set @Commit4 = '';",
   832  			"call dolt_commit_hash_out(@Commit4, '-am', 'inserting into table t');",
   833  		},
   834  		Assertions: []queries.ScriptTestAssertion{
   835  			{
   836  				Query:    "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type from dolt_diff(@Commit1, @Commit2, 't');",
   837  				Expected: []sql.Row{{1, "one", "two", nil, nil, nil, "added"}},
   838  			},
   839  			{
   840  				Query:    "SELECT COUNT(*) from dolt_diff(@Commit2, @Commit3, 't');",
   841  				Expected: []sql.Row{{0}},
   842  			},
   843  			{
   844  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type from dolt_diff(@Commit3, @Commit4, 't');",
   845  				Expected: []sql.Row{
   846  					{1, "uno", "dos", 1, "one", "two", "modified"},
   847  					{2, "two", "three", nil, nil, nil, "added"},
   848  					{3, "three", "four", nil, nil, nil, "added"},
   849  				},
   850  			},
   851  			{
   852  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type from dolt_diff(@Commit4, @Commit3, 't');",
   853  				Expected: []sql.Row{
   854  					{1, "one", "two", 1, "uno", "dos", "modified"},
   855  					{nil, nil, nil, 2, "two", "three", "removed"},
   856  					{nil, nil, nil, 3, "three", "four", "removed"},
   857  				},
   858  			},
   859  			{
   860  				// Table t2 had no changes between Commit3 and Commit4, so results should be empty
   861  				Query:    "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type  from dolt_diff(@Commit3, @Commit4, 'T2');",
   862  				Expected: []sql.Row{},
   863  			},
   864  			{
   865  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type  from dolt_diff(@Commit1, @Commit4, 't');",
   866  				Expected: []sql.Row{
   867  					{1, "uno", "dos", nil, nil, nil, "added"},
   868  					{2, "two", "three", nil, nil, nil, "added"},
   869  					{3, "three", "four", nil, nil, nil, "added"},
   870  				},
   871  			},
   872  			{
   873  				// Reverse the to/from commits to see the diff from the other direction
   874  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type  from dolt_diff(@Commit4, @Commit1, 'T');",
   875  				Expected: []sql.Row{
   876  					{nil, nil, nil, 1, "uno", "dos", "removed"},
   877  					{nil, nil, nil, 2, "two", "three", "removed"},
   878  					{nil, nil, nil, 3, "three", "four", "removed"},
   879  				},
   880  			},
   881  			{
   882  				Query: `
   883  SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type
   884  from dolt_diff(@Commit1, @Commit2, 't')
   885  inner join t on to_pk = t.pk;`,
   886  				Expected: []sql.Row{{1, "one", "two", nil, nil, nil, "added"}},
   887  			},
   888  			{
   889  				Query: `
   890  SELECT to_pk, from_c1, to_c1, from_c1, to_c1, diff_type, diff_type
   891  from dolt_diff(@Commit1, @Commit2, 't') inner join dolt_diff(@Commit1, @Commit3, 't');`,
   892  				ExpectedErr: sql.ErrAmbiguousColumnName,
   893  			},
   894  			{
   895  				Query: `
   896  SELECT a.to_pk, a.from_c1, a.to_c1, b.from_c1, b.to_c1, a.diff_type, b.diff_type
   897  from dolt_diff(@Commit1, @Commit2, 't') a inner join dolt_diff(@Commit1, @Commit3, 't') b
   898  on a.to_pk = b.to_pk;`,
   899  				Expected: []sql.Row{
   900  					{1, nil, "one", nil, "one", "added", "added"},
   901  				},
   902  			},
   903  		},
   904  	},
   905  	{
   906  		Name: "WORKING and STAGED",
   907  		SetUpScript: []string{
   908  			"set @Commit0 = HashOf('HEAD');",
   909  
   910  			"create table t (pk int primary key, c1 text, c2 text);",
   911  			"call dolt_add('.')",
   912  			"insert into t values (1, 'one', 'two'), (2, 'three', 'four');",
   913  			"set @Commit1 = '';",
   914  			"call dolt_commit_hash_out(@Commit1, '-am', 'inserting two rows into table t');",
   915  
   916  			"insert into t values (3, 'five', 'six');",
   917  			"delete from t where pk = 2",
   918  			"update t set c2 = '100' where pk = 1",
   919  		},
   920  		Assertions: []queries.ScriptTestAssertion{
   921  			{
   922  				Query: "SELECT from_pk, from_c1, from_c2, to_pk, to_c1, to_c2, diff_type from dolt_diff(@Commit1, 'WORKING', 't') order by coalesce(from_pk, to_pk)",
   923  				Expected: []sql.Row{
   924  					{1, "one", "two", 1, "one", "100", "modified"},
   925  					{2, "three", "four", nil, nil, nil, "removed"},
   926  					{nil, nil, nil, 3, "five", "six", "added"},
   927  				},
   928  			},
   929  			{
   930  				Query: "SELECT from_pk, from_c1, from_c2, to_pk, to_c1, to_c2, diff_type from dolt_diff('STAGED', 'WORKING', 't') order by coalesce(from_pk, to_pk);",
   931  				Expected: []sql.Row{
   932  					{1, "one", "two", 1, "one", "100", "modified"},
   933  					{2, "three", "four", nil, nil, nil, "removed"},
   934  					{nil, nil, nil, 3, "five", "six", "added"},
   935  				},
   936  			},
   937  			{
   938  				Query: "SELECT from_pk, from_c1, from_c2, to_pk, to_c1, to_c2, diff_type from dolt_diff('STAGED..WORKING', 't') order by coalesce(from_pk, to_pk);",
   939  				Expected: []sql.Row{
   940  					{1, "one", "two", 1, "one", "100", "modified"},
   941  					{2, "three", "four", nil, nil, nil, "removed"},
   942  					{nil, nil, nil, 3, "five", "six", "added"},
   943  				},
   944  			},
   945  			{
   946  				Query: "SELECT from_pk, from_c1, from_c2, to_pk, to_c1, to_c2, diff_type from dolt_diff('WORKING', 'STAGED', 't') order by coalesce(from_pk, to_pk);",
   947  				Expected: []sql.Row{
   948  					{1, "one", "100", 1, "one", "two", "modified"},
   949  					{nil, nil, nil, 2, "three", "four", "added"},
   950  					{3, "five", "six", nil, nil, nil, "removed"},
   951  				},
   952  			},
   953  			{
   954  				Query:    "SELECT from_pk, from_c1, from_c2, to_pk, to_c1, to_c2, diff_type from dolt_diff('WORKING', 'WORKING', 't') order by coalesce(from_pk, to_pk);",
   955  				Expected: []sql.Row{},
   956  			},
   957  			{
   958  				Query:    "SELECT from_pk, from_c1, from_c2, to_pk, to_c1, to_c2, diff_type from dolt_diff('WORKING..WORKING', 't') order by coalesce(from_pk, to_pk);",
   959  				Expected: []sql.Row{},
   960  			},
   961  			{
   962  				Query:    "SELECT from_pk, from_c1, from_c2, to_pk, to_c1, to_c2, diff_type from dolt_diff('STAGED', 'STAGED', 't') order by coalesce(from_pk, to_pk);",
   963  				Expected: []sql.Row{},
   964  			},
   965  			{
   966  				Query:            "call dolt_add('.')",
   967  				SkipResultsCheck: true,
   968  			},
   969  			{
   970  				Query:    "SELECT from_pk, from_c1, from_c2, to_pk, to_c1, to_c2, diff_type from dolt_diff('WORKING', 'STAGED', 't') order by coalesce(from_pk, to_pk);",
   971  				Expected: []sql.Row{},
   972  			},
   973  			{
   974  				Query: "SELECT from_pk, from_c1, from_c2, to_pk, to_c1, to_c2, diff_type from dolt_diff('HEAD', 'STAGED', 't') order by coalesce(from_pk, to_pk);",
   975  				Expected: []sql.Row{
   976  					{1, "one", "two", 1, "one", "100", "modified"},
   977  					{2, "three", "four", nil, nil, nil, "removed"},
   978  					{nil, nil, nil, 3, "five", "six", "added"},
   979  				},
   980  			},
   981  		},
   982  	},
   983  	{
   984  		Name: "diff with branch refs",
   985  		SetUpScript: []string{
   986  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
   987  			"call dolt_add('.')",
   988  			"set @Commit1 = '';",
   989  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
   990  
   991  			"insert into t values(1, 'one', 'two');",
   992  			"set @Commit2 = '';",
   993  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting row 1 into t in main');",
   994  
   995  			"CALL DOLT_checkout('-b', 'branch1');",
   996  			"alter table t drop column c2;",
   997  			"set @Commit3 = '';",
   998  			"call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c2 in branch1');",
   999  
  1000  			"delete from t where pk=1;",
  1001  			"set @Commit4 = '';",
  1002  			"call dolt_commit_hash_out(@Commit4, '-am', 'deleting row 1 in branch1');",
  1003  
  1004  			"insert into t values (2, 'two');",
  1005  			"set @Commit5 = '';",
  1006  			"call dolt_commit_hash_out(@Commit5, '-am', 'inserting row 2 in branch1');",
  1007  
  1008  			"CALL DOLT_checkout('main');",
  1009  			"insert into t values (2, 'two', 'three');",
  1010  			"set @Commit6 = '';",
  1011  			"call dolt_commit_hash_out(@Commit6, '-am', 'inserting row 2 in main');",
  1012  		},
  1013  		Assertions: []queries.ScriptTestAssertion{
  1014  			{
  1015  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, from_c2, diff_type from dolt_diff('main', 'branch1', 't');",
  1016  				Expected: []sql.Row{
  1017  					{nil, nil, 1, "one", "two", "removed"},
  1018  					{2, "two", 2, "two", "three", "modified"},
  1019  				},
  1020  			},
  1021  			{
  1022  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, from_c2, diff_type from dolt_diff('main..branch1', 't');",
  1023  				Expected: []sql.Row{
  1024  					{nil, nil, 1, "one", "two", "removed"},
  1025  					{2, "two", 2, "two", "three", "modified"},
  1026  				},
  1027  			},
  1028  			{
  1029  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, diff_type from dolt_diff('branch1', 'main', 't');",
  1030  				Expected: []sql.Row{
  1031  					{1, "one", "two", nil, nil, "added"},
  1032  					{2, "two", "three", 2, "two", "modified"},
  1033  				},
  1034  			},
  1035  			{
  1036  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, diff_type from dolt_diff('branch1..main', 't');",
  1037  				Expected: []sql.Row{
  1038  					{1, "one", "two", nil, nil, "added"},
  1039  					{2, "two", "three", 2, "two", "modified"},
  1040  				},
  1041  			},
  1042  			{
  1043  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, from_c2, diff_type from dolt_diff('main~', 'branch1', 't');",
  1044  				Expected: []sql.Row{
  1045  					{nil, nil, 1, "one", "two", "removed"},
  1046  					{2, "two", nil, nil, nil, "added"},
  1047  				},
  1048  			},
  1049  			{
  1050  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, from_c2, diff_type from dolt_diff('main~..branch1', 't');",
  1051  				Expected: []sql.Row{
  1052  					{nil, nil, 1, "one", "two", "removed"},
  1053  					{2, "two", nil, nil, nil, "added"},
  1054  				},
  1055  			},
  1056  
  1057  			// Three dot
  1058  			{
  1059  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, from_c2, diff_type from dolt_diff('main...branch1', 't');",
  1060  				Expected: []sql.Row{
  1061  					{nil, nil, 1, "one", "two", "removed"},
  1062  					{2, "two", nil, nil, nil, "added"},
  1063  				},
  1064  			},
  1065  			{
  1066  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, diff_type from dolt_diff('branch1...main', 't');",
  1067  				Expected: []sql.Row{
  1068  					{2, "two", "three", nil, nil, "added"},
  1069  				},
  1070  			},
  1071  			{
  1072  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, from_c2, diff_type from dolt_diff('main~...branch1', 't');",
  1073  				Expected: []sql.Row{
  1074  					{nil, nil, 1, "one", "two", "removed"},
  1075  					{2, "two", nil, nil, nil, "added"},
  1076  				},
  1077  			},
  1078  			{
  1079  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, from_c2, diff_type from dolt_diff('main...branch1~', 't');",
  1080  				Expected: []sql.Row{
  1081  					{nil, nil, 1, "one", "two", "removed"},
  1082  				},
  1083  			},
  1084  		},
  1085  	},
  1086  	{
  1087  		Name: "schema modification: drop and recreate column with same type",
  1088  		SetUpScript: []string{
  1089  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  1090  			"call dolt_add('.')",
  1091  			"set @Commit1 = '';",
  1092  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
  1093  
  1094  			"insert into t values(1, 'one', 'two'), (2, 'two', 'three');",
  1095  			"set @Commit2 = '';",
  1096  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');",
  1097  
  1098  			"alter table t drop column c2;",
  1099  			"set @Commit3 = '';",
  1100  			"call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c2');",
  1101  
  1102  			"alter table t add column c2 varchar(20);",
  1103  			"insert into t values (3, 'three', 'four');",
  1104  			"update t set c2='foo' where pk=1;",
  1105  			"set @Commit4 = '';",
  1106  			"call dolt_commit_hash_out(@Commit4, '-am', 'adding column c2, inserting, and updating data');",
  1107  		},
  1108  		Assertions: []queries.ScriptTestAssertion{
  1109  			{
  1110  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type from dolt_diff(@Commit1, @Commit2, 't');",
  1111  				Expected: []sql.Row{
  1112  					{1, "one", "two", nil, nil, nil, "added"},
  1113  					{2, "two", "three", nil, nil, nil, "added"},
  1114  				},
  1115  			},
  1116  			{
  1117  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, from_c2, diff_type from dolt_diff(@Commit2, @Commit3, 't');",
  1118  				Expected: []sql.Row{
  1119  					{1, "one", 1, "one", "two", "modified"},
  1120  					{2, "two", 2, "two", "three", "modified"},
  1121  				},
  1122  			},
  1123  			{
  1124  				Query:       "SELECT to_c2 from dolt_diff(@Commit2, @Commit3, 't');",
  1125  				ExpectedErr: sql.ErrColumnNotFound,
  1126  			},
  1127  			{
  1128  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, diff_type from dolt_diff(@Commit3, @Commit4, 't');",
  1129  				Expected: []sql.Row{
  1130  					{1, "one", "foo", 1, "one", "modified"},
  1131  					// This row doesn't show up as changed because adding a column doesn't touch the row data.
  1132  					//{2, "two", nil, 2, "two", "modified"},
  1133  					{3, "three", "four", nil, nil, "added"},
  1134  				},
  1135  			},
  1136  			{
  1137  				Query:       "SELECT from_c2 from dolt_diff(@Commit3, @Commit4, 't');",
  1138  				ExpectedErr: sql.ErrColumnNotFound,
  1139  			},
  1140  			{
  1141  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type from dolt_diff(@Commit1, @Commit4, 't');",
  1142  				Expected: []sql.Row{
  1143  					{1, "one", "foo", nil, nil, nil, "added"},
  1144  					{2, "two", nil, nil, nil, nil, "added"},
  1145  					{3, "three", "four", nil, nil, nil, "added"},
  1146  				},
  1147  			},
  1148  		},
  1149  	},
  1150  	{
  1151  		Name: "schema modification: rename columns",
  1152  		SetUpScript: []string{
  1153  			"create table t (pk int primary key, c1 varchar(20), c2 int);",
  1154  			"call dolt_add('.')",
  1155  			"set @Commit1 = '';",
  1156  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
  1157  
  1158  			"insert into t values(1, 'one', -1), (2, 'two', -2);",
  1159  			"set @Commit2 = '';",
  1160  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');",
  1161  
  1162  			"alter table t rename column c2 to c3;",
  1163  			"set @Commit3 = '';",
  1164  			"call dolt_commit_hash_out(@Commit3, '-am', 'renaming column c2 to c3');",
  1165  
  1166  			"insert into t values (3, 'three', -3);",
  1167  			"update t set c3=1 where pk=1;",
  1168  			"set @Commit4 = '';",
  1169  			"call dolt_commit_hash_out(@Commit4, '-am', 'inserting and updating data');",
  1170  
  1171  			"alter table t rename column c3 to c2;",
  1172  			"insert into t values (4, 'four', -4);",
  1173  			"set @Commit5 = '';",
  1174  			"call dolt_commit_hash_out(@Commit5, '-am', 'renaming column c3 to c2, and inserting data');",
  1175  		},
  1176  		Assertions: []queries.ScriptTestAssertion{
  1177  			{
  1178  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type from dolt_diff(@Commit1, @Commit2, 't');",
  1179  				Expected: []sql.Row{
  1180  					{1, "one", -1, nil, nil, nil, "added"},
  1181  					{2, "two", -2, nil, nil, nil, "added"},
  1182  				},
  1183  			},
  1184  			{
  1185  				Query:       "SELECT to_c2 from dolt_diff(@Commit2, @Commit3, 't');",
  1186  				ExpectedErr: sql.ErrColumnNotFound,
  1187  			},
  1188  			{
  1189  				Query:    "SELECT to_pk, to_c1, to_c3, from_pk, from_c1, from_c2, diff_type from dolt_diff(@Commit2, @Commit3, 't');",
  1190  				Expected: []sql.Row{},
  1191  			},
  1192  			{
  1193  				Query: "SELECT to_pk, to_c1, to_c3, from_pk, from_c1, from_c3, diff_type from dolt_diff(@Commit3, @Commit4, 't');",
  1194  				Expected: []sql.Row{
  1195  					{3, "three", -3, nil, nil, nil, "added"},
  1196  					{1, "one", 1, 1, "one", -1, "modified"},
  1197  				},
  1198  			},
  1199  			{
  1200  				Query:       "SELECT from_c2 from dolt_diff(@Commit4, @Commit5, 't');",
  1201  				ExpectedErr: sql.ErrColumnNotFound,
  1202  			},
  1203  			{
  1204  				Query:       "SELECT to_c3 from dolt_diff(@Commit4, @Commit5, 't');",
  1205  				ExpectedErr: sql.ErrColumnNotFound,
  1206  			},
  1207  			{
  1208  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c3, diff_type from dolt_diff(@Commit4, @Commit5, 't');",
  1209  				Expected: []sql.Row{
  1210  					{4, "four", -4, nil, nil, nil, "added"},
  1211  				},
  1212  			},
  1213  			{
  1214  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type from dolt_diff(@Commit1, @Commit5, 't');",
  1215  				Expected: []sql.Row{
  1216  					{1, "one", 1, nil, nil, nil, "added"},
  1217  					{2, "two", -2, nil, nil, nil, "added"},
  1218  					{3, "three", -3, nil, nil, nil, "added"},
  1219  					{4, "four", -4, nil, nil, nil, "added"},
  1220  				},
  1221  			},
  1222  		},
  1223  	},
  1224  	{
  1225  		Name: "schema modification: drop and rename columns with different types",
  1226  		SetUpScript: []string{
  1227  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  1228  			"call dolt_add('.')",
  1229  			"set @Commit1 = '';",
  1230  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
  1231  
  1232  			"insert into t values(1, 'one', 'asdf'), (2, 'two', '2');",
  1233  			"set @Commit2 = '';",
  1234  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');",
  1235  
  1236  			"alter table t drop column c2;",
  1237  			"set @Commit3 = '';",
  1238  			"call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c2');",
  1239  
  1240  			"insert into t values (3, 'three');",
  1241  			"update t set c1='fdsa' where pk=1;",
  1242  			"set @Commit4 = '';",
  1243  			"call dolt_commit_hash_out(@Commit4, '-am', 'inserting and updating data');",
  1244  
  1245  			"alter table t add column c2 int;",
  1246  			"insert into t values (4, 'four', -4);",
  1247  			"set @Commit5 = '';",
  1248  			"call dolt_commit_hash_out(@Commit5, '-am', 'adding column c2, and inserting data');",
  1249  		},
  1250  		Assertions: []queries.ScriptTestAssertion{
  1251  			{
  1252  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type from dolt_diff(@Commit1, @Commit2, 't');",
  1253  				Expected: []sql.Row{
  1254  					{1, "one", "asdf", nil, nil, nil, "added"},
  1255  					{2, "two", "2", nil, nil, nil, "added"},
  1256  				},
  1257  			},
  1258  			{
  1259  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, from_c2, diff_type from dolt_diff(@Commit2, @Commit3, 't');",
  1260  				Expected: []sql.Row{
  1261  					{1, "one", 1, "one", "asdf", "modified"},
  1262  					{2, "two", 2, "two", "2", "modified"},
  1263  				},
  1264  			},
  1265  			{
  1266  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, diff_type from dolt_diff(@Commit3, @Commit4, 't');",
  1267  				Expected: []sql.Row{
  1268  					{3, "three", nil, nil, "added"},
  1269  					{1, "fdsa", 1, "one", "modified"},
  1270  				},
  1271  			},
  1272  			{
  1273  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, diff_type from dolt_diff(@Commit4, @Commit5, 't');",
  1274  				Expected: []sql.Row{
  1275  					{4, "four", -4, nil, nil, "added"},
  1276  				},
  1277  			},
  1278  			{
  1279  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type from dolt_diff(@Commit1, @Commit5, 't');",
  1280  				Expected: []sql.Row{
  1281  					{1, "fdsa", nil, nil, nil, nil, "added"},
  1282  					{2, "two", nil, nil, nil, nil, "added"},
  1283  					{3, "three", nil, nil, nil, nil, "added"},
  1284  					{4, "four", -4, nil, nil, nil, "added"},
  1285  				},
  1286  			},
  1287  		},
  1288  	},
  1289  	{
  1290  		Name: "new table",
  1291  		SetUpScript: []string{
  1292  			"create table t1 (a int primary key, b int)",
  1293  			"insert into t1 values (1,2)",
  1294  		},
  1295  		Assertions: []queries.ScriptTestAssertion{
  1296  			{
  1297  				Query:    "select to_a, to_b, from_commit, to_commit, diff_type from dolt_diff('HEAD', 'WORKING', 't1')",
  1298  				Expected: []sql.Row{{1, 2, "HEAD", "WORKING", "added"}},
  1299  			},
  1300  			{
  1301  				Query:    "select to_a, from_b, from_commit, to_commit, diff_type from dolt_diff('HEAD', 'WORKING', 't1')",
  1302  				Expected: []sql.Row{{1, nil, "HEAD", "WORKING", "added"}},
  1303  			},
  1304  			{
  1305  				Query:    "select from_a, from_b, to_a, from_commit, to_commit, diff_type from dolt_diff('WORKING', 'HEAD', 't1')",
  1306  				Expected: []sql.Row{{1, 2, nil, "WORKING", "HEAD", "removed"}},
  1307  			},
  1308  		},
  1309  	},
  1310  	{
  1311  		Name: "dropped table",
  1312  		SetUpScript: []string{
  1313  			"create table t1 (a int primary key, b int)",
  1314  			"call dolt_add('.')",
  1315  			"insert into t1 values (1,2)",
  1316  			"call dolt_commit('-am', 'new table')",
  1317  			"drop table t1",
  1318  			"call dolt_commit('-am', 'dropped table')",
  1319  		},
  1320  		Assertions: []queries.ScriptTestAssertion{
  1321  			{
  1322  				Query:    "select from_a, from_b, from_commit, to_commit, diff_type from dolt_diff('HEAD~', 'HEAD', 't1')",
  1323  				Expected: []sql.Row{{1, 2, "HEAD~", "HEAD", "removed"}},
  1324  			},
  1325  			{
  1326  				Query:    "select from_a, from_b, from_commit, to_commit, diff_type from dolt_diff('HEAD~..HEAD', 't1')",
  1327  				Expected: []sql.Row{{1, 2, "HEAD~", "HEAD", "removed"}},
  1328  			},
  1329  		},
  1330  	},
  1331  	{
  1332  		Name: "renamed table",
  1333  		SetUpScript: []string{
  1334  			"create table t1 (a int primary key, b int)",
  1335  			"call dolt_add('.')",
  1336  			"insert into t1 values (1,2)",
  1337  			"call dolt_commit('-am', 'new table')",
  1338  			"alter table t1 rename to t2",
  1339  			"call dolt_add('.')",
  1340  			"insert into t2 values (3,4)",
  1341  			"call dolt_commit('-am', 'renamed table')",
  1342  		},
  1343  		Assertions: []queries.ScriptTestAssertion{
  1344  			{
  1345  				Query:    "select to_a, to_b, from_commit, to_commit, diff_type from dolt_diff('HEAD~', 'HEAD', 't2')",
  1346  				Expected: []sql.Row{{3, 4, "HEAD~", "HEAD", "added"}},
  1347  			},
  1348  			{
  1349  				Query:    "select to_a, to_b, from_commit, to_commit, diff_type from dolt_diff('HEAD~..HEAD', 't2')",
  1350  				Expected: []sql.Row{{3, 4, "HEAD~", "HEAD", "added"}},
  1351  			},
  1352  			{
  1353  				// Maybe confusing? We match the old table name as well
  1354  				Query:    "select to_a, to_b, from_commit, to_commit, diff_type from dolt_diff('HEAD~', 'HEAD', 't1')",
  1355  				Expected: []sql.Row{{3, 4, "HEAD~", "HEAD", "added"}},
  1356  			},
  1357  		},
  1358  	},
  1359  	{
  1360  		Name: "Renaming a primary key column shows PK values in both the to and from columns",
  1361  		SetUpScript: []string{
  1362  			"CREATE TABLE t1 (pk int PRIMARY KEY, col1 int);",
  1363  			"INSERT INTO t1 VALUES (1, 1);",
  1364  			"CREATE TABLE t2 (pk1a int, pk1b int, col1 int, PRIMARY KEY (pk1a, pk1b));",
  1365  			"INSERT INTO t2 VALUES (1, 1, 1);",
  1366  			"CALL DOLT_ADD('.')",
  1367  			"CALL DOLT_COMMIT('-am', 'initial');",
  1368  
  1369  			"ALTER TABLE t1 RENAME COLUMN pk to pk2;",
  1370  			"UPDATE t1 set col1 = 100;",
  1371  			"ALTER TABLE t2 RENAME COLUMN pk1a to pk2a;",
  1372  			"ALTER TABLE t2 RENAME COLUMN pk1b to pk2b;",
  1373  			"UPDATE t2 set col1 = 100;",
  1374  			"CALL DOLT_COMMIT('-am', 'edit');",
  1375  		},
  1376  		Assertions: []queries.ScriptTestAssertion{
  1377  			{
  1378  				Query:    "select to_pk2, to_col1, from_pk, from_col1, diff_type from dolt_diff('HEAD~', 'HEAD', 't1')",
  1379  				Expected: []sql.Row{{1, 100, 1, 1, "modified"}},
  1380  			},
  1381  			{
  1382  				Query:    "select to_pk2, to_col1, from_pk, from_col1, diff_type from dolt_diff('HEAD~..HEAD', 't1')",
  1383  				Expected: []sql.Row{{1, 100, 1, 1, "modified"}},
  1384  			},
  1385  			{
  1386  				Query:    "select to_pk2a, to_pk2b, to_col1, from_pk1a, from_pk1b, from_col1, diff_type from dolt_diff('HEAD~', 'HEAD', 't2');",
  1387  				Expected: []sql.Row{{1, 1, 100, 1, 1, 1, "modified"}},
  1388  			},
  1389  			{
  1390  				Query:    "select to_pk2a, to_pk2b, to_col1, from_pk1a, from_pk1b, from_col1, diff_type from dolt_diff('HEAD~..HEAD', 't2');",
  1391  				Expected: []sql.Row{{1, 1, 100, 1, 1, 1, "modified"}},
  1392  			},
  1393  		},
  1394  	},
  1395  	{
  1396  		Name: "diff on dolt_schemas on events",
  1397  		SetUpScript: []string{
  1398  			"CREATE TABLE messages (id INT PRIMARY KEY AUTO_INCREMENT, message VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL);",
  1399  			"CREATE EVENT IF NOT EXISTS msg_event ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 YEAR DISABLE DO INSERT INTO messages(message,created_at) VALUES('Test Dolt Event 1',NOW());",
  1400  			"CREATE EVENT my_commit ON SCHEDULE EVERY 1 DAY DISABLE DO CALL DOLT_COMMIT('--allow-empty','-am','my daily commit');",
  1401  			"CALL DOLT_ADD('.')",
  1402  			"SET @Commit1 = '';",
  1403  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating table and events')",
  1404  		},
  1405  		Assertions: []queries.ScriptTestAssertion{
  1406  			{
  1407  				Query: "SELECT type, name FROM dolt_schemas;",
  1408  				Expected: []sql.Row{
  1409  					{"event", "msg_event"},
  1410  					{"event", "my_commit"},
  1411  				},
  1412  			},
  1413  			{
  1414  				Query:       "CREATE EVENT msg_event ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 YEAR DISABLE DO INSERT INTO messages(message,created_at) VALUES('Test Dolt Event 2',NOW());",
  1415  				ExpectedErr: sql.ErrEventAlreadyExists,
  1416  			},
  1417  			{
  1418  				Query:            "DROP EVENT msg_event;",
  1419  				SkipResultsCheck: true,
  1420  			},
  1421  			{
  1422  				Query:            "CREATE EVENT msg_event ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 YEAR ON COMPLETION PRESERVE DISABLE DO INSERT INTO messages(message,created_at) VALUES('Test Dolt Event 2',NOW());",
  1423  				SkipResultsCheck: true,
  1424  			},
  1425  			{
  1426  				Query:    "SELECT from_type, from_name, to_name, diff_type FROM DOLT_DIFF('HEAD', 'WORKING', 'dolt_schemas')",
  1427  				Expected: []sql.Row{{"event", "msg_event", "msg_event", "modified"}},
  1428  			},
  1429  			{
  1430  				Query: "SELECT type, name FROM dolt_schemas;",
  1431  				Expected: []sql.Row{
  1432  					{"event", "msg_event"},
  1433  					{"event", "my_commit"},
  1434  				},
  1435  			},
  1436  		},
  1437  	},
  1438  }
  1439  
  1440  var DiffStatTableFunctionScriptTests = []queries.ScriptTest{
  1441  	{
  1442  		Name: "invalid arguments",
  1443  		SetUpScript: []string{
  1444  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  1445  			"call dolt_add('.')",
  1446  			"set @Commit1 = '';",
  1447  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
  1448  
  1449  			"insert into t values(1, 'one', 'two'), (2, 'two', 'three');",
  1450  			"set @Commit2 = '';",
  1451  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');",
  1452  		},
  1453  		Assertions: []queries.ScriptTestAssertion{
  1454  			{
  1455  				Query:       "SELECT * from dolt_diff_stat();",
  1456  				ExpectedErr: sql.ErrInvalidArgumentNumber,
  1457  			},
  1458  			{
  1459  				Query:       "SELECT * from dolt_diff_stat('t');",
  1460  				ExpectedErr: sql.ErrInvalidArgumentNumber,
  1461  			},
  1462  			{
  1463  				Query:       "SELECT * from dolt_diff_stat('t', @Commit1, @Commit2, 'extra');",
  1464  				ExpectedErr: sql.ErrInvalidArgumentNumber,
  1465  			},
  1466  			{
  1467  				Query:       "SELECT * from dolt_diff_stat(null, null, null);",
  1468  				ExpectedErr: sql.ErrInvalidArgumentDetails,
  1469  			},
  1470  			{
  1471  				Query:       "SELECT * from dolt_diff_stat(123, @Commit1, @Commit2);",
  1472  				ExpectedErr: sql.ErrInvalidArgumentDetails,
  1473  			},
  1474  			{
  1475  				Query:       "SELECT * from dolt_diff_stat('t', 123, @Commit2);",
  1476  				ExpectedErr: sql.ErrInvalidArgumentDetails,
  1477  			},
  1478  			{
  1479  				Query:       "SELECT * from dolt_diff_stat('t', @Commit1, 123);",
  1480  				ExpectedErr: sql.ErrInvalidArgumentDetails,
  1481  			},
  1482  			{
  1483  				Query:          "SELECT * from dolt_diff_stat('fake-branch', @Commit2, 't');",
  1484  				ExpectedErrStr: "branch not found: fake-branch",
  1485  			},
  1486  			{
  1487  				Query:          "SELECT * from dolt_diff_stat('fake-branch..main', 't');",
  1488  				ExpectedErrStr: "branch not found: fake-branch",
  1489  			},
  1490  			{
  1491  				Query:          "SELECT * from dolt_diff_stat(@Commit1, 'fake-branch', 't');",
  1492  				ExpectedErrStr: "branch not found: fake-branch",
  1493  			},
  1494  			{
  1495  				Query:          "SELECT * from dolt_diff_stat('main..fake-branch', 't');",
  1496  				ExpectedErrStr: "branch not found: fake-branch",
  1497  			},
  1498  			{
  1499  				Query:       "SELECT * from dolt_diff_stat(@Commit1, @Commit2, 'doesnotexist');",
  1500  				ExpectedErr: sql.ErrTableNotFound,
  1501  			},
  1502  			{
  1503  				Query:       "SELECT * from dolt_diff_stat('main^..main', 'doesnotexist');",
  1504  				ExpectedErr: sql.ErrTableNotFound,
  1505  			},
  1506  			{
  1507  				Query:       "SELECT * from dolt_diff_stat(@Commit1, concat('fake', '-', 'branch'), 't');",
  1508  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
  1509  			},
  1510  			{
  1511  				Query:       "SELECT * from dolt_diff_stat(hashof('main'), @Commit2, 't');",
  1512  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
  1513  			},
  1514  			{
  1515  				Query:       "SELECT * from dolt_diff_stat(@Commit1, @Commit2, LOWER('T'));",
  1516  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
  1517  			},
  1518  			{
  1519  				Query:       "SELECT * from dolt_diff_stat('main..main~', LOWER('T'));",
  1520  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
  1521  			},
  1522  		},
  1523  	},
  1524  	{
  1525  		Name: "basic case with single table",
  1526  		SetUpScript: []string{
  1527  			"set @Commit0 = HashOf('HEAD');",
  1528  			"set @Commit1 = '';",
  1529  			"call dolt_commit_hash_out(@Commit1, '--allow-empty', '-m', 'creating table t');",
  1530  
  1531  			// create table t only
  1532  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  1533  			"call dolt_add('.')",
  1534  			"set @Commit2 = '';",
  1535  			"call dolt_commit_hash_out(@Commit2, '-am', 'creating table t');",
  1536  
  1537  			// insert 1 row into t
  1538  			"insert into t values(1, 'one', 'two');",
  1539  			"set @Commit3 = '';",
  1540  			"call dolt_commit_hash_out(@Commit3, '-am', 'inserting 1 into table t');",
  1541  
  1542  			// insert 2 rows into t and update two cells
  1543  			"insert into t values(2, 'two', 'three'), (3, 'three', 'four');",
  1544  			"update t set c1='uno', c2='dos' where pk=1;",
  1545  			"set @Commit4 = '';",
  1546  			"call dolt_commit_hash_out(@Commit4, '-am', 'inserting 2 into table t');",
  1547  
  1548  			// drop table t only
  1549  			"drop table t;",
  1550  			"set @Commit5 = '';",
  1551  			"call dolt_commit_hash_out(@Commit5, '-am', 'drop table t');",
  1552  		},
  1553  		Assertions: []queries.ScriptTestAssertion{
  1554  			{
  1555  				// table is added, no data diff, result is empty
  1556  				Query:    "SELECT * from dolt_diff_stat(@Commit1, @Commit2, 't');",
  1557  				Expected: []sql.Row{},
  1558  			},
  1559  			{
  1560  				Query:    "SELECT * from dolt_diff_stat(@Commit2, @Commit3, 't');",
  1561  				Expected: []sql.Row{{"t", 0, 1, 0, 0, 3, 0, 0, 0, 1, 0, 3}},
  1562  			},
  1563  			{
  1564  				Query:    "SELECT * from dolt_diff_stat(@Commit3, @Commit4, 't');",
  1565  				Expected: []sql.Row{{"t", 0, 2, 0, 1, 6, 0, 2, 1, 3, 3, 9}},
  1566  			},
  1567  			{
  1568  				// change from and to commits
  1569  				Query:    "SELECT * from dolt_diff_stat(@Commit4, @Commit3, 't');",
  1570  				Expected: []sql.Row{{"t", 0, 0, 2, 1, 0, 6, 2, 3, 1, 9, 3}},
  1571  			},
  1572  			{
  1573  				// table is dropped
  1574  				Query:    "SELECT * from dolt_diff_stat(@Commit4, @Commit5, 't');",
  1575  				Expected: []sql.Row{{"t", 0, 0, 3, 0, 0, 9, 0, 3, 0, 9, 0}},
  1576  			},
  1577  			{
  1578  				Query:    "SELECT * from dolt_diff_stat(@Commit1, @Commit4, 't');",
  1579  				Expected: []sql.Row{{"t", 0, 3, 0, 0, 9, 0, 0, 0, 3, 0, 9}},
  1580  			},
  1581  			{
  1582  				Query:       "SELECT * from dolt_diff_stat(@Commit1, @Commit5, 't');",
  1583  				ExpectedErr: sql.ErrTableNotFound,
  1584  			},
  1585  			{
  1586  				Query: `
  1587  SELECT *
  1588  from dolt_diff_stat(@Commit3, @Commit4, 't') 
  1589  inner join t as of @Commit3 on rows_unmodified = t.pk;`,
  1590  				Expected: []sql.Row{},
  1591  			},
  1592  		},
  1593  	},
  1594  	{
  1595  		Name: "basic case with single keyless table",
  1596  		SetUpScript: []string{
  1597  			"set @Commit0 = HashOf('HEAD');",
  1598  			"set @Commit1 = '';",
  1599  			"call dolt_commit_hash_out(@Commit1, '--allow-empty', '-m', 'creating table t');",
  1600  
  1601  			// create table t only
  1602  			"create table t (id int, c1 varchar(20), c2 varchar(20));",
  1603  			"call dolt_add('.')",
  1604  			"set @Commit2 = '';",
  1605  			"call dolt_commit_hash_out(@Commit2, '-am', 'creating table t');",
  1606  
  1607  			// insert 1 row into t
  1608  			"insert into t values(1, 'one', 'two');",
  1609  			"set @Commit3 = '';",
  1610  			"call dolt_commit_hash_out(@Commit3, '-am', 'inserting 1 into table t');",
  1611  
  1612  			// insert 2 rows into t and update two cells
  1613  			"insert into t values(2, 'two', 'three'), (3, 'three', 'four');",
  1614  			"update t set c1='uno', c2='dos' where id=1;",
  1615  			"set @Commit4 = '';",
  1616  			"call dolt_commit_hash_out(@Commit4, '-am', 'inserting 2 into table t');",
  1617  
  1618  			// drop table t only
  1619  			"drop table t;",
  1620  			"set @Commit5 = '';",
  1621  			"call dolt_commit_hash_out(@Commit5, '-am', 'drop table t');",
  1622  		},
  1623  		Assertions: []queries.ScriptTestAssertion{
  1624  			{
  1625  				// table is added, no data diff, result is empty
  1626  				Query:    "SELECT * from dolt_diff_stat(@Commit1, @Commit2, 't');",
  1627  				Expected: []sql.Row{},
  1628  			},
  1629  			{
  1630  				Query:    "SELECT * from dolt_diff_stat(@Commit2, @Commit3, 't');",
  1631  				Expected: []sql.Row{{"t", nil, 1, 0, nil, nil, nil, nil, nil, nil, nil, nil}},
  1632  			},
  1633  			{
  1634  				// TODO : (correct result is commented out)
  1635  				//      update row for keyless table deletes the row and insert the new row
  1636  				// 		this causes row added = 3 and row deleted = 1
  1637  				Query: "SELECT * from dolt_diff_stat(@Commit3, @Commit4, 't');",
  1638  				//Expected:         []sql.Row{{"t", nil, 2, 0, nil, nil, nil, nil, nil, nil, nil, nil}},
  1639  				Expected: []sql.Row{{"t", nil, 3, 1, nil, nil, nil, nil, nil, nil, nil, nil}},
  1640  			},
  1641  			{
  1642  				Query: "SELECT * from dolt_diff_stat(@Commit4, @Commit3, 't');",
  1643  				//Expected:         []sql.Row{{"t", nil, 0, 2, nil, nil, nil, nil, nil, nil, nil, nil}},
  1644  				Expected: []sql.Row{{"t", nil, 1, 3, nil, nil, nil, nil, nil, nil, nil, nil}},
  1645  			},
  1646  			{
  1647  				// table is dropped
  1648  				Query:    "SELECT * from dolt_diff_stat(@Commit4, @Commit5, 't');",
  1649  				Expected: []sql.Row{{"t", nil, 0, 3, nil, nil, nil, nil, nil, nil, nil, nil}},
  1650  			},
  1651  			{
  1652  				Query:    "SELECT * from dolt_diff_stat(@Commit1, @Commit4, 't');",
  1653  				Expected: []sql.Row{{"t", nil, 3, 0, nil, nil, nil, nil, nil, nil, nil, nil}},
  1654  			},
  1655  			{
  1656  				Query:       "SELECT * from dolt_diff_stat(@Commit1, @Commit5, 't');",
  1657  				ExpectedErr: sql.ErrTableNotFound,
  1658  			},
  1659  		},
  1660  	},
  1661  	{
  1662  		Name: "basic case with multiple tables",
  1663  		SetUpScript: []string{
  1664  			"set @Commit0 = HashOf('HEAD');",
  1665  
  1666  			// add table t with 1 row
  1667  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  1668  			"insert into t values(1, 'one', 'two');",
  1669  			"call dolt_add('.')",
  1670  			"set @Commit1 = '';",
  1671  			"call dolt_commit_hash_out(@Commit1, '-am', 'inserting into table t');",
  1672  
  1673  			// add table t2 with 1 row
  1674  			"create table t2 (pk int primary key, c1 varchar(20), c2 varchar(20));",
  1675  			"insert into t2 values(100, 'hundred', 'hundert');",
  1676  			"call dolt_add('.')",
  1677  			"set @Commit2 = '';",
  1678  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting into table t2');",
  1679  
  1680  			// changes on both tables
  1681  			"insert into t values(2, 'two', 'three'), (3, 'three', 'four'), (4, 'four', 'five');",
  1682  			"update t set c1='uno', c2='dos' where pk=1;",
  1683  			"insert into t2 values(101, 'hundred one', 'one');",
  1684  			"set @Commit3 = '';",
  1685  			"call dolt_commit_hash_out(@Commit3, '-am', 'inserting into table t');",
  1686  
  1687  			// changes on both tables
  1688  			"delete from t where c2 = 'four';",
  1689  			"update t2 set c2='zero' where pk=100;",
  1690  			"set @Commit4 = '';",
  1691  			"call dolt_commit_hash_out(@Commit4, '-am', 'inserting into table t');",
  1692  
  1693  			// create keyless table
  1694  			"create table keyless (id int);",
  1695  		},
  1696  		Assertions: []queries.ScriptTestAssertion{
  1697  			{
  1698  				Query:    "SELECT * from dolt_diff_stat(@Commit0, @Commit1);",
  1699  				Expected: []sql.Row{{"t", 0, 1, 0, 0, 3, 0, 0, 0, 1, 0, 3}},
  1700  			},
  1701  			{
  1702  				Query:    "SELECT * from dolt_diff_stat(@Commit1, @Commit2);",
  1703  				Expected: []sql.Row{{"t2", 0, 1, 0, 0, 3, 0, 0, 0, 1, 0, 3}},
  1704  			},
  1705  			{
  1706  				Query:    "SELECT * from dolt_diff_stat(@Commit2, @Commit3);",
  1707  				Expected: []sql.Row{{"t", 0, 3, 0, 1, 9, 0, 2, 1, 4, 3, 12}, {"t2", 1, 1, 0, 0, 3, 0, 0, 1, 2, 3, 6}},
  1708  			},
  1709  			{
  1710  				Query:    "SELECT * from dolt_diff_stat(@Commit3, @Commit4);",
  1711  				Expected: []sql.Row{{"t", 3, 0, 1, 0, 0, 3, 0, 4, 3, 12, 9}, {"t2", 1, 0, 0, 1, 0, 0, 1, 2, 2, 6, 6}},
  1712  			},
  1713  			{
  1714  				Query:    "SELECT * from dolt_diff_stat(@Commit4, @Commit2);",
  1715  				Expected: []sql.Row{{"t", 0, 0, 2, 1, 0, 6, 2, 3, 1, 9, 3}, {"t2", 0, 0, 1, 1, 0, 3, 1, 2, 1, 6, 3}},
  1716  			},
  1717  			{
  1718  				Query:    "SELECT * from dolt_diff_stat(@Commit3, 'WORKING');",
  1719  				Expected: []sql.Row{{"t", 3, 0, 1, 0, 0, 3, 0, 4, 3, 12, 9}, {"t2", 1, 0, 0, 1, 0, 0, 1, 2, 2, 6, 6}},
  1720  			},
  1721  		},
  1722  	},
  1723  	{
  1724  		Name: "WORKING and STAGED",
  1725  		SetUpScript: []string{
  1726  			"set @Commit0 = HashOf('HEAD');",
  1727  
  1728  			"create table t (pk int primary key, c1 text, c2 text);",
  1729  			"call dolt_add('.')",
  1730  			"insert into t values (1, 'one', 'two'), (2, 'three', 'four');",
  1731  			"set @Commit1 = '';",
  1732  			"call dolt_commit_hash_out(@Commit1, '-am', 'inserting two rows into table t');",
  1733  
  1734  			"insert into t values (3, 'five', 'six');",
  1735  			"delete from t where pk = 2",
  1736  			"update t set c2 = '100' where pk = 1",
  1737  		},
  1738  		Assertions: []queries.ScriptTestAssertion{
  1739  			{
  1740  				Query:    "SELECT * from dolt_diff_stat(@Commit1, 'WORKING', 't')",
  1741  				Expected: []sql.Row{{"t", 0, 1, 1, 1, 3, 3, 1, 2, 2, 6, 6}},
  1742  			},
  1743  			{
  1744  				Query:    "SELECT * from dolt_diff_stat('STAGED', 'WORKING', 't')",
  1745  				Expected: []sql.Row{{"t", 0, 1, 1, 1, 3, 3, 1, 2, 2, 6, 6}},
  1746  			},
  1747  			{
  1748  				Query:    "SELECT * from dolt_diff_stat('STAGED..WORKING', 't')",
  1749  				Expected: []sql.Row{{"t", 0, 1, 1, 1, 3, 3, 1, 2, 2, 6, 6}},
  1750  			},
  1751  			{
  1752  				Query:    "SELECT * from dolt_diff_stat('WORKING', 'STAGED', 't')",
  1753  				Expected: []sql.Row{{"t", 0, 1, 1, 1, 3, 3, 1, 2, 2, 6, 6}},
  1754  			},
  1755  			{
  1756  				Query:    "SELECT * from dolt_diff_stat('WORKING', 'WORKING', 't')",
  1757  				Expected: []sql.Row{},
  1758  			},
  1759  			{
  1760  				Query:    "SELECT * from dolt_diff_stat('WORKING..WORKING', 't')",
  1761  				Expected: []sql.Row{},
  1762  			},
  1763  			{
  1764  				Query:    "SELECT * from dolt_diff_stat('STAGED', 'STAGED', 't')",
  1765  				Expected: []sql.Row{},
  1766  			},
  1767  			{
  1768  				Query:            "call dolt_add('.')",
  1769  				SkipResultsCheck: true,
  1770  			},
  1771  			{
  1772  				Query:    "SELECT * from dolt_diff_stat('WORKING', 'STAGED', 't')",
  1773  				Expected: []sql.Row{},
  1774  			},
  1775  			{
  1776  				Query:    "SELECT * from dolt_diff_stat('HEAD', 'STAGED', 't')",
  1777  				Expected: []sql.Row{{"t", 0, 1, 1, 1, 3, 3, 1, 2, 2, 6, 6}},
  1778  			},
  1779  		},
  1780  	},
  1781  	{
  1782  		Name: "diff with branch refs",
  1783  		SetUpScript: []string{
  1784  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  1785  			"call dolt_add('.')",
  1786  			"set @Commit1 = '';",
  1787  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
  1788  
  1789  			"insert into t values(1, 'one', 'two');",
  1790  			"set @Commit2 = '';",
  1791  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting row 1 into t in main');",
  1792  
  1793  			"CALL DOLT_checkout('-b', 'branch1');",
  1794  			"alter table t drop column c2;",
  1795  			"set @Commit3 = '';",
  1796  			"call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c2 in branch1');",
  1797  
  1798  			"delete from t where pk=1;",
  1799  			"set @Commit4 = '';",
  1800  			"call dolt_commit_hash_out(@Commit4, '-am', 'deleting row 1 in branch1');",
  1801  
  1802  			"insert into t values (2, 'two');",
  1803  			"set @Commit5 = '';",
  1804  			"call dolt_commit_hash_out(@Commit5, '-am', 'inserting row 2 in branch1');",
  1805  
  1806  			"CALL DOLT_checkout('main');",
  1807  			"insert into t values (2, 'two', 'three');",
  1808  			"set @Commit6 = '';",
  1809  			"call dolt_commit_hash_out(@Commit6, '-am', 'inserting row 2 in main');",
  1810  
  1811  			"create table newtable (pk int primary key);",
  1812  			"insert into newtable values (1), (2);",
  1813  			"set @Commit7 = '';",
  1814  			"call dolt_commit_hash_out(@Commit7, '-Am', 'new table newtable');",
  1815  		},
  1816  		Assertions: []queries.ScriptTestAssertion{
  1817  			{
  1818  				Query:    "SELECT * from dolt_diff_stat('main', 'branch1', 't');",
  1819  				Expected: []sql.Row{{"t", 0, 0, 1, 1, 0, 4, 0, 2, 1, 6, 2}},
  1820  			},
  1821  			{
  1822  				Query:    "SELECT * from dolt_diff_stat('main..branch1', 't');",
  1823  				Expected: []sql.Row{{"t", 0, 0, 1, 1, 0, 4, 0, 2, 1, 6, 2}},
  1824  			},
  1825  			{
  1826  				Query: "SELECT * from dolt_diff_stat('main', 'branch1');",
  1827  				Expected: []sql.Row{
  1828  					{"t", 0, 0, 1, 1, 0, 4, 0, 2, 1, 6, 2},
  1829  					{"newtable", 0, 0, 2, 0, 0, 2, 0, 2, 0, 2, 0},
  1830  				},
  1831  			},
  1832  			{
  1833  				Query: "SELECT * from dolt_diff_stat('main..branch1');",
  1834  				Expected: []sql.Row{
  1835  					{"t", 0, 0, 1, 1, 0, 4, 0, 2, 1, 6, 2},
  1836  					{"newtable", 0, 0, 2, 0, 0, 2, 0, 2, 0, 2, 0},
  1837  				},
  1838  			},
  1839  			{
  1840  				Query:    "SELECT * from dolt_diff_stat('branch1', 'main', 't');",
  1841  				Expected: []sql.Row{{"t", 0, 1, 0, 1, 4, 0, 1, 1, 2, 2, 6}},
  1842  			},
  1843  			{
  1844  				Query:    "SELECT * from dolt_diff_stat('branch1..main', 't');",
  1845  				Expected: []sql.Row{{"t", 0, 1, 0, 1, 4, 0, 1, 1, 2, 2, 6}},
  1846  			},
  1847  			{
  1848  				Query:    "SELECT * from dolt_diff_stat('main~2', 'branch1', 't');",
  1849  				Expected: []sql.Row{{"t", 0, 1, 1, 0, 2, 3, 0, 1, 1, 3, 2}},
  1850  			},
  1851  			{
  1852  				Query:    "SELECT * from dolt_diff_stat('main~2..branch1', 't');",
  1853  				Expected: []sql.Row{{"t", 0, 1, 1, 0, 2, 3, 0, 1, 1, 3, 2}},
  1854  			},
  1855  
  1856  			// Three dot
  1857  			{
  1858  				Query:    "SELECT * from dolt_diff_stat('main...branch1', 't');",
  1859  				Expected: []sql.Row{{"t", 0, 1, 1, 0, 2, 3, 0, 1, 1, 3, 2}},
  1860  			},
  1861  			{
  1862  				Query:    "SELECT * from dolt_diff_stat('main...branch1');",
  1863  				Expected: []sql.Row{{"t", 0, 1, 1, 0, 2, 3, 0, 1, 1, 3, 2}},
  1864  			},
  1865  			{
  1866  				Query:    "SELECT * from dolt_diff_stat('branch1...main', 't');",
  1867  				Expected: []sql.Row{{"t", 1, 1, 0, 0, 3, 0, 0, 1, 2, 3, 6}},
  1868  			},
  1869  			{
  1870  				Query: "SELECT * from dolt_diff_stat('branch1...main');",
  1871  				Expected: []sql.Row{
  1872  					{"t", 1, 1, 0, 0, 3, 0, 0, 1, 2, 3, 6},
  1873  					{"newtable", 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 2},
  1874  				},
  1875  			},
  1876  			{
  1877  				Query:    "SELECT * from dolt_diff_stat('branch1...main^');",
  1878  				Expected: []sql.Row{{"t", 1, 1, 0, 0, 3, 0, 0, 1, 2, 3, 6}},
  1879  			},
  1880  			{
  1881  				Query:    "SELECT * from dolt_diff_stat('branch1...main', 'newtable');",
  1882  				Expected: []sql.Row{{"newtable", 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 2}},
  1883  			},
  1884  			{
  1885  				Query:    "SELECT * from dolt_diff_stat('main...main', 'newtable');",
  1886  				Expected: []sql.Row{},
  1887  			},
  1888  		},
  1889  	},
  1890  	{
  1891  		Name: "schema modification: drop and add column",
  1892  		SetUpScript: []string{
  1893  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  1894  			"call dolt_add('.');",
  1895  			"insert into t values (1, 'one', 'two'), (2, 'two', 'three');",
  1896  			"set @Commit1 = '';",
  1897  			"call dolt_commit_hash_out(@Commit1, '-am', 'inserting row 1, 2 into t');",
  1898  
  1899  			// drop 1 column and add 1 row
  1900  			"alter table t drop column c2;",
  1901  			"set @Commit2 = '';",
  1902  			"call dolt_commit_hash_out(@Commit2, '-am', 'dropping column c2');",
  1903  
  1904  			// drop 1 column and add 1 row
  1905  			"insert into t values (3, 'three');",
  1906  			"set @Commit3 = '';",
  1907  			"call dolt_commit_hash_out(@Commit3, '-am', 'inserting row 3');",
  1908  
  1909  			// add 1 column and 1 row and update
  1910  			"alter table t add column c2 varchar(20);",
  1911  			"insert into t values (4, 'four', 'five');",
  1912  			"update t set c2='foo' where pk=1;",
  1913  			"set @Commit4 = '';",
  1914  			"call dolt_commit_hash_out(@Commit4, '-am', 'adding column c2, inserting, and updating data');",
  1915  		},
  1916  		Assertions: []queries.ScriptTestAssertion{
  1917  			{
  1918  				Query:    "SELECT * from dolt_diff_stat(@Commit1, @Commit2, 't');",
  1919  				Expected: []sql.Row{{"t", 0, 0, 0, 2, 0, 2, 0, 2, 2, 6, 4}},
  1920  			},
  1921  			{
  1922  				Query:    "SELECT * from dolt_diff_stat(@Commit2, @Commit3, 't');",
  1923  				Expected: []sql.Row{{"t", 2, 1, 0, 0, 2, 0, 0, 2, 3, 4, 6}},
  1924  			},
  1925  			{
  1926  				Query:    "SELECT * from dolt_diff_stat(@Commit1, @Commit3, 't');",
  1927  				Expected: []sql.Row{{"t", 0, 1, 0, 2, 2, 2, 0, 2, 3, 6, 6}},
  1928  			},
  1929  			{
  1930  				Query:    "SELECT * from dolt_diff_stat(@Commit3, @Commit4, 't');",
  1931  				Expected: []sql.Row{{"t", 2, 1, 0, 1, 6, 0, 1, 3, 4, 6, 12}},
  1932  			},
  1933  			{
  1934  				Query:    "SELECT * from dolt_diff_stat(@Commit1, @Commit4, 't');",
  1935  				Expected: []sql.Row{{"t", 0, 2, 0, 2, 6, 0, 2, 2, 4, 6, 12}},
  1936  			},
  1937  		},
  1938  	},
  1939  	{
  1940  		Name: "schema modification: rename columns",
  1941  		SetUpScript: []string{
  1942  			"create table t (pk int primary key, c1 varchar(20), c2 int);",
  1943  			"call dolt_add('.')",
  1944  			"set @Commit1 = '';",
  1945  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
  1946  
  1947  			"insert into t values(1, 'one', -1), (2, 'two', -2);",
  1948  			"set @Commit2 = '';",
  1949  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');",
  1950  
  1951  			"alter table t rename column c2 to c3;",
  1952  			"set @Commit3 = '';",
  1953  			"call dolt_commit_hash_out(@Commit3, '-am', 'renaming column c2 to c3');",
  1954  
  1955  			"insert into t values (3, 'three', -3);",
  1956  			"update t set c3=1 where pk=1;",
  1957  			"set @Commit4 = '';",
  1958  			"call dolt_commit_hash_out(@Commit4, '-am', 'inserting and updating data');",
  1959  
  1960  			"alter table t rename column c3 to c2;",
  1961  			"insert into t values (4, 'four', -4);",
  1962  			"set @Commit5 = '';",
  1963  			"call dolt_commit_hash_out(@Commit5, '-am', 'renaming column c3 to c2, and inserting data');",
  1964  		},
  1965  		Assertions: []queries.ScriptTestAssertion{
  1966  			{
  1967  				Query:    "SELECT * from dolt_diff_stat(@Commit1, @Commit2, 't');",
  1968  				Expected: []sql.Row{{"t", 0, 2, 0, 0, 6, 0, 0, 0, 2, 0, 6}},
  1969  			},
  1970  			{
  1971  				Query:    "SELECT * from dolt_diff_stat(@Commit2, @Commit3, 't');",
  1972  				Expected: []sql.Row{},
  1973  			},
  1974  			{
  1975  				Query:    "SELECT * from dolt_diff_stat(@Commit3, @Commit4, 't');",
  1976  				Expected: []sql.Row{{"t", 1, 1, 0, 1, 3, 0, 1, 2, 3, 6, 9}},
  1977  			},
  1978  			{
  1979  				Query:    "SELECT * from dolt_diff_stat(@Commit4, @Commit5, 't');",
  1980  				Expected: []sql.Row{{"t", 3, 1, 0, 0, 3, 0, 0, 3, 4, 9, 12}},
  1981  			},
  1982  			{
  1983  				Query:    "SELECT * from dolt_diff_stat(@Commit1, @Commit5, 't');",
  1984  				Expected: []sql.Row{{"t", 0, 4, 0, 0, 12, 0, 0, 0, 4, 0, 12}},
  1985  			},
  1986  		},
  1987  	},
  1988  	{
  1989  		Name: "new table",
  1990  		SetUpScript: []string{
  1991  			"create table t1 (a int primary key, b int)",
  1992  		},
  1993  		Assertions: []queries.ScriptTestAssertion{
  1994  			{
  1995  				Query:    "select * from dolt_diff_stat('HEAD', 'WORKING')",
  1996  				Expected: []sql.Row{},
  1997  			},
  1998  			{
  1999  				Query:    "select * from dolt_diff_stat('WORKING', 'HEAD')",
  2000  				Expected: []sql.Row{},
  2001  			},
  2002  			{
  2003  				Query:            "insert into t1 values (1,2)",
  2004  				SkipResultsCheck: true,
  2005  			},
  2006  			{
  2007  				Query:    "select * from dolt_diff_stat('HEAD', 'WORKING', 't1')",
  2008  				Expected: []sql.Row{{"t1", 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 2}},
  2009  			},
  2010  			{
  2011  				Query:    "select * from dolt_diff_stat('WORKING', 'HEAD', 't1')",
  2012  				Expected: []sql.Row{{"t1", 0, 0, 1, 0, 0, 2, 0, 1, 0, 2, 0}},
  2013  			},
  2014  		},
  2015  	},
  2016  	{
  2017  		Name: "dropped table",
  2018  		SetUpScript: []string{
  2019  			"create table t1 (a int primary key, b int)",
  2020  			"call dolt_add('.')",
  2021  			"insert into t1 values (1,2)",
  2022  			"call dolt_commit('-am', 'new table')",
  2023  			"drop table t1",
  2024  			"call dolt_commit('-am', 'dropped table')",
  2025  		},
  2026  		Assertions: []queries.ScriptTestAssertion{
  2027  			{
  2028  				Query:    "select * from dolt_diff_stat('HEAD~', 'HEAD', 't1')",
  2029  				Expected: []sql.Row{{"t1", 0, 0, 1, 0, 0, 2, 0, 1, 0, 2, 0}},
  2030  			},
  2031  			{
  2032  				Query:    "select * from dolt_diff_stat('HEAD', 'HEAD~', 't1')",
  2033  				Expected: []sql.Row{{"t1", 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 2}},
  2034  			},
  2035  		},
  2036  	},
  2037  	{
  2038  		Name: "renamed table",
  2039  		SetUpScript: []string{
  2040  			"create table t1 (a int primary key, b int)",
  2041  			"call dolt_add('.')",
  2042  			"insert into t1 values (1,2)",
  2043  			"call dolt_commit('-am', 'new table')",
  2044  			"alter table t1 rename to t2",
  2045  			"call dolt_add('.')",
  2046  			"insert into t2 values (3,4)",
  2047  			"call dolt_commit('-am', 'renamed table')",
  2048  		},
  2049  		Assertions: []queries.ScriptTestAssertion{
  2050  			{
  2051  				Query:    "select * from dolt_diff_stat('HEAD~', 'HEAD', 't2')",
  2052  				Expected: []sql.Row{{"t2", 1, 1, 0, 0, 2, 0, 0, 1, 2, 2, 4}},
  2053  			},
  2054  			{
  2055  				Query:    "select * from dolt_diff_stat('HEAD~..HEAD', 't2')",
  2056  				Expected: []sql.Row{{"t2", 1, 1, 0, 0, 2, 0, 0, 1, 2, 2, 4}},
  2057  			},
  2058  			{
  2059  				// Old table name can be matched as well
  2060  				Query:    "select * from dolt_diff_stat('HEAD~', 'HEAD', 't1')",
  2061  				Expected: []sql.Row{{"t1", 1, 1, 0, 0, 2, 0, 0, 1, 2, 2, 4}},
  2062  			},
  2063  			{
  2064  				// Old table name can be matched as well
  2065  				Query:    "select * from dolt_diff_stat('HEAD~..HEAD', 't1')",
  2066  				Expected: []sql.Row{{"t1", 1, 1, 0, 0, 2, 0, 0, 1, 2, 2, 4}},
  2067  			},
  2068  		},
  2069  	},
  2070  	{
  2071  		Name: "add multiple columns, then set and unset a value. Should not show a diff",
  2072  		SetUpScript: []string{
  2073  			"CREATE table t (pk int primary key);",
  2074  			"Insert into t values (1);",
  2075  			"CALL DOLT_ADD('.');",
  2076  			"CALL DOLT_COMMIT('-am', 'setup');",
  2077  			"alter table t add column col1 int;",
  2078  			"alter table t add column col2 int;",
  2079  			"CALL DOLT_ADD('.');",
  2080  			"CALL DOLT_COMMIT('-am', 'add columns');",
  2081  			"UPDATE t set col1 = 1 where pk = 1;",
  2082  			"UPDATE t set col1 = null where pk = 1;",
  2083  			"CALL DOLT_COMMIT('--allow-empty', '-am', 'fix short tuple');",
  2084  		},
  2085  		Assertions: []queries.ScriptTestAssertion{
  2086  			{
  2087  				Query:    "SELECT * from dolt_diff_stat('HEAD~2', 'HEAD');",
  2088  				Expected: []sql.Row{{"t", 1, 0, 0, 0, 2, 0, 0, 1, 1, 1, 3}},
  2089  			},
  2090  			{
  2091  				Query:    "SELECT * from dolt_diff_stat('HEAD~', 'HEAD');",
  2092  				Expected: []sql.Row{},
  2093  			},
  2094  		},
  2095  	},
  2096  	{
  2097  		Name: "pk set change should throw an error for 3 argument dolt_diff_stat",
  2098  		SetUpScript: []string{
  2099  			"CREATE table t (pk int primary key);",
  2100  			"INSERT INTO t values (1);",
  2101  			"CALL DOLT_COMMIT('-Am', 'table with row');",
  2102  			"ALTER TABLE t ADD col1 int not null default 0;",
  2103  			"ALTER TABLE t drop primary key;",
  2104  			"ALTER TABLE t add primary key (pk, col1);",
  2105  			"CALL DOLT_COMMIT('-am', 'add secondary column with primary key');",
  2106  		},
  2107  		Assertions: []queries.ScriptTestAssertion{
  2108  			{
  2109  				Query:          "SELECT * from dolt_diff_stat('HEAD~', 'HEAD', 't');",
  2110  				ExpectedErrStr: "failed to compute diff stat for table t: primary key set changed",
  2111  			},
  2112  		},
  2113  	},
  2114  	{
  2115  		Name: "pk set change should report warning for 2 argument dolt_diff_stat",
  2116  		SetUpScript: []string{
  2117  			"CREATE table t (pk int primary key);",
  2118  			"INSERT INTO t values (1);",
  2119  			"CREATE table t2 (pk int primary key);",
  2120  			"INSERT INTO t2 values (2);",
  2121  			"CALL DOLT_COMMIT('-Am', 'multiple tables');",
  2122  			"ALTER TABLE t ADD col1 int not null default 0;",
  2123  			"ALTER TABLE t drop primary key;",
  2124  			"ALTER TABLE t add primary key (pk, col1);",
  2125  			"INSERT INTO t2 values (3), (4), (5);",
  2126  			"CALL DOLT_COMMIT('-am', 'add secondary column with primary key to t');",
  2127  		},
  2128  		Assertions: []queries.ScriptTestAssertion{
  2129  			{
  2130  				Query: "SELECT * from dolt_diff_stat('HEAD~', 'HEAD')",
  2131  				Expected: []sql.Row{
  2132  					{"t", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  2133  					{"t2", 1, 3, 0, 0, 3, 0, 0, 1, 4, 1, 4},
  2134  				},
  2135  				ExpectedWarning:       dtables.PrimaryKeyChangeWarningCode,
  2136  				ExpectedWarningsCount: 1,
  2137  			},
  2138  		},
  2139  	},
  2140  }
  2141  
  2142  var DiffSummaryTableFunctionScriptTests = []queries.ScriptTest{
  2143  	{
  2144  		Name: "invalid arguments",
  2145  		SetUpScript: []string{
  2146  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  2147  			"call dolt_add('.')",
  2148  			"set @Commit1 = '';",
  2149  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
  2150  
  2151  			"insert into t values(1, 'one', 'two'), (2, 'two', 'three');",
  2152  			"set @Commit2 = '';",
  2153  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');",
  2154  		},
  2155  		Assertions: []queries.ScriptTestAssertion{
  2156  			{
  2157  				Query:       "SELECT * from dolt_diff_summary();",
  2158  				ExpectedErr: sql.ErrInvalidArgumentNumber,
  2159  			},
  2160  			{
  2161  				Query:       "SELECT * from dolt_diff_summary('t');",
  2162  				ExpectedErr: sql.ErrInvalidArgumentNumber,
  2163  			},
  2164  			{
  2165  				Query:       "SELECT * from dolt_diff_summary('t', @Commit1, @Commit2, 'extra');",
  2166  				ExpectedErr: sql.ErrInvalidArgumentNumber,
  2167  			},
  2168  			{
  2169  				Query:       "SELECT * from dolt_diff_summary(null, null, null);",
  2170  				ExpectedErr: sql.ErrInvalidArgumentDetails,
  2171  			},
  2172  			{
  2173  				Query:       "SELECT * from dolt_diff_summary(123, @Commit1, @Commit2);",
  2174  				ExpectedErr: sql.ErrInvalidArgumentDetails,
  2175  			},
  2176  			{
  2177  				Query:       "SELECT * from dolt_diff_summary('t', 123, @Commit2);",
  2178  				ExpectedErr: sql.ErrInvalidArgumentDetails,
  2179  			},
  2180  			{
  2181  				Query:       "SELECT * from dolt_diff_summary('t', @Commit1, 123);",
  2182  				ExpectedErr: sql.ErrInvalidArgumentDetails,
  2183  			},
  2184  			{
  2185  				Query:          "SELECT * from dolt_diff_summary('fake-branch', @Commit2, 't');",
  2186  				ExpectedErrStr: "branch not found: fake-branch",
  2187  			},
  2188  			{
  2189  				Query:          "SELECT * from dolt_diff_summary('fake-branch..main', 't');",
  2190  				ExpectedErrStr: "branch not found: fake-branch",
  2191  			},
  2192  			{
  2193  				Query:          "SELECT * from dolt_diff_summary(@Commit1, 'fake-branch', 't');",
  2194  				ExpectedErrStr: "branch not found: fake-branch",
  2195  			},
  2196  			{
  2197  				Query:          "SELECT * from dolt_diff_summary('main..fake-branch', 't');",
  2198  				ExpectedErrStr: "branch not found: fake-branch",
  2199  			},
  2200  			{
  2201  				Query:       "SELECT * from dolt_diff_summary(@Commit1, concat('fake', '-', 'branch'), 't');",
  2202  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
  2203  			},
  2204  			{
  2205  				Query:       "SELECT * from dolt_diff_summary(hashof('main'), @Commit2, 't');",
  2206  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
  2207  			},
  2208  			{
  2209  				Query:       "SELECT * from dolt_diff_summary(@Commit1, @Commit2, LOWER('T'));",
  2210  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
  2211  			},
  2212  		},
  2213  	},
  2214  	{
  2215  		Name: "basic case with single table",
  2216  		SetUpScript: []string{
  2217  			"set @Commit0 = HashOf('HEAD');",
  2218  			"set @Commit1 = '';",
  2219  			"call dolt_commit_hash_out(@Commit1, '--allow-empty', '-m', 'creating table t');",
  2220  
  2221  			// create table t only
  2222  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  2223  			"call dolt_add('.')",
  2224  			"set @Commit2 = '';",
  2225  			"call dolt_commit_hash_out(@Commit2, '-am', 'creating table t');",
  2226  
  2227  			// insert 1 row into t
  2228  			"insert into t values(1, 'one', 'two');",
  2229  			"set @Commit3 = '';",
  2230  			"call dolt_commit_hash_out(@Commit3, '-am', 'inserting 1 into table t');",
  2231  
  2232  			// insert 2 rows into t and update two cells
  2233  			"insert into t values(2, 'two', 'three'), (3, 'three', 'four');",
  2234  			"update t set c1='uno', c2='dos' where pk=1;",
  2235  			"set @Commit4 = '';",
  2236  			"call dolt_commit_hash_out(@Commit4, '-am', 'inserting 2 into table t');",
  2237  
  2238  			// drop table t only
  2239  			"drop table t;",
  2240  			"set @Commit5 = '';",
  2241  			"call dolt_commit_hash_out(@Commit5, '-am', 'drop table t');",
  2242  		},
  2243  		Assertions: []queries.ScriptTestAssertion{
  2244  			{
  2245  				// table does not exist, empty result
  2246  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit2, 'doesnotexist');",
  2247  				Expected: []sql.Row{},
  2248  			},
  2249  			{
  2250  				// table is added, no data changes
  2251  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit2, 't');",
  2252  				Expected: []sql.Row{{"", "t", "added", false, true}},
  2253  			},
  2254  			{
  2255  				Query:    "SELECT * from dolt_diff_summary(@Commit2, @Commit3, 't');",
  2256  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2257  			},
  2258  			{
  2259  				Query:    "SELECT * from dolt_diff_summary(@Commit3, @Commit4, 't');",
  2260  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2261  			},
  2262  			{
  2263  				// change from and to commits
  2264  				Query:    "SELECT * from dolt_diff_summary(@Commit4, @Commit3, 't');",
  2265  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2266  			},
  2267  			{
  2268  				// table is dropped
  2269  				Query:    "SELECT * from dolt_diff_summary(@Commit4, @Commit5, 't');",
  2270  				Expected: []sql.Row{{"t", "", "dropped", true, true}},
  2271  			},
  2272  			{
  2273  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit4, 't');",
  2274  				Expected: []sql.Row{{"", "t", "added", true, true}},
  2275  			},
  2276  			{
  2277  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit5, 't');",
  2278  				Expected: []sql.Row{},
  2279  			},
  2280  		},
  2281  	},
  2282  	{
  2283  		Name: "basic case with single keyless table",
  2284  		SetUpScript: []string{
  2285  			"set @Commit0 = HashOf('HEAD');",
  2286  			"set @Commit1 = '';",
  2287  			"call dolt_commit_hash_out(@Commit1, '--allow-empty', '-m', 'creating table t');",
  2288  
  2289  			// create table t only
  2290  			"create table t (id int, c1 varchar(20), c2 varchar(20));",
  2291  			"call dolt_add('.')",
  2292  			"set @Commit2 = '';",
  2293  			"call dolt_commit_hash_out(@Commit2, '-am', 'creating table t');",
  2294  
  2295  			// insert 1 row into t
  2296  			"insert into t values(1, 'one', 'two');",
  2297  			"set @Commit3 = '';",
  2298  			"call dolt_commit_hash_out(@Commit3, '-am', 'inserting 1 into table t');",
  2299  
  2300  			// insert 2 rows into t and update two cells
  2301  			"insert into t values(2, 'two', 'three'), (3, 'three', 'four');",
  2302  			"update t set c1='uno', c2='dos' where id=1;",
  2303  			"set @Commit4 = '';",
  2304  			"call dolt_commit_hash_out(@Commit4, '-am', 'inserting 2 into table t');",
  2305  
  2306  			// drop table t only
  2307  			"drop table t;",
  2308  			"set @Commit5 = '';",
  2309  			"call dolt_commit_hash_out(@Commit5, '-am', 'drop table t');",
  2310  		},
  2311  		Assertions: []queries.ScriptTestAssertion{
  2312  			{
  2313  				// table is added, no data diff, result is empty
  2314  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit2, 't');",
  2315  				Expected: []sql.Row{{"", "t", "added", false, true}},
  2316  			},
  2317  			{
  2318  				Query:    "SELECT * from dolt_diff_summary(@Commit2, @Commit3, 't');",
  2319  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2320  			},
  2321  			{
  2322  				Query:    "SELECT * from dolt_diff_summary(@Commit3, @Commit4, 't');",
  2323  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2324  			},
  2325  			{
  2326  				Query:    "SELECT * from dolt_diff_summary(@Commit4, @Commit3, 't');",
  2327  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2328  			},
  2329  			{
  2330  				// table is dropped
  2331  				Query:    "SELECT * from dolt_diff_summary(@Commit4, @Commit5, 't');",
  2332  				Expected: []sql.Row{{"t", "", "dropped", true, true}},
  2333  			},
  2334  			{
  2335  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit4, 't');",
  2336  				Expected: []sql.Row{{"", "t", "added", true, true}},
  2337  			},
  2338  			{
  2339  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit5, 't');",
  2340  				Expected: []sql.Row{},
  2341  			},
  2342  		},
  2343  	},
  2344  	{
  2345  		Name: "basic case with multiple tables",
  2346  		SetUpScript: []string{
  2347  			"set @Commit0 = HashOf('HEAD');",
  2348  
  2349  			// add table t with 1 row
  2350  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  2351  			"insert into t values(1, 'one', 'two');",
  2352  			"call dolt_add('.')",
  2353  			"set @Commit1 = '';",
  2354  			"call dolt_commit_hash_out(@Commit1, '-am', 'inserting into table t');",
  2355  
  2356  			// add table t2 with 1 row
  2357  			"create table t2 (pk int primary key, c1 varchar(20), c2 varchar(20));",
  2358  			"insert into t2 values(100, 'hundred', 'hundert');",
  2359  			"call dolt_add('.')",
  2360  			"set @Commit2 = '';",
  2361  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting into table t2');",
  2362  
  2363  			// changes on both tables
  2364  			"insert into t values(2, 'two', 'three'), (3, 'three', 'four'), (4, 'four', 'five');",
  2365  			"update t set c1='uno', c2='dos' where pk=1;",
  2366  			"insert into t2 values(101, 'hundred one', 'one');",
  2367  			"set @Commit3 = '';",
  2368  			"call dolt_commit_hash_out(@Commit3, '-am', 'inserting into table t');",
  2369  
  2370  			// changes on both tables
  2371  			"delete from t where c2 = 'four';",
  2372  			"update t2 set c2='zero' where pk=100;",
  2373  			"set @Commit4 = '';",
  2374  			"call dolt_commit_hash_out(@Commit4, '-am', 'inserting into table t');",
  2375  
  2376  			// create keyless table
  2377  			"create table keyless (id int);",
  2378  		},
  2379  		Assertions: []queries.ScriptTestAssertion{
  2380  			{
  2381  				Query:    "SELECT * from dolt_diff_summary(@Commit0, @Commit1);",
  2382  				Expected: []sql.Row{{"", "t", "added", true, true}},
  2383  			},
  2384  			{
  2385  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit2);",
  2386  				Expected: []sql.Row{{"", "t2", "added", true, true}},
  2387  			},
  2388  			{
  2389  				Query: "SELECT * from dolt_diff_summary(@Commit2, @Commit3);",
  2390  				Expected: []sql.Row{
  2391  					{"t", "t", "modified", true, false},
  2392  					{"t2", "t2", "modified", true, false},
  2393  				},
  2394  			},
  2395  			{
  2396  				Query: "SELECT * from dolt_diff_summary(@Commit3, @Commit4);",
  2397  				Expected: []sql.Row{
  2398  					{"t", "t", "modified", true, false},
  2399  					{"t2", "t2", "modified", true, false},
  2400  				},
  2401  			},
  2402  			{
  2403  				Query: "SELECT * from dolt_diff_summary(@Commit0, @Commit4);",
  2404  				Expected: []sql.Row{
  2405  					{"", "t", "added", true, true},
  2406  					{"", "t2", "added", true, true},
  2407  				},
  2408  			},
  2409  			{
  2410  				Query: "SELECT * from dolt_diff_summary(@Commit4, @Commit2);",
  2411  
  2412  				Expected: []sql.Row{
  2413  					{"t", "t", "modified", true, false},
  2414  					{"t2", "t2", "modified", true, false},
  2415  				},
  2416  			},
  2417  			{
  2418  				Query: "SELECT * from dolt_diff_summary(@Commit3, 'WORKING');",
  2419  				Expected: []sql.Row{
  2420  					{"t", "t", "modified", true, false},
  2421  					{"t2", "t2", "modified", true, false},
  2422  					{"", "keyless", "added", false, true}},
  2423  			},
  2424  		},
  2425  	},
  2426  	{
  2427  		Name: "WORKING and STAGED",
  2428  		SetUpScript: []string{
  2429  			"set @Commit0 = HashOf('HEAD');",
  2430  
  2431  			"create table t (pk int primary key, c1 text, c2 text);",
  2432  			"call dolt_add('.')",
  2433  			"insert into t values (1, 'one', 'two'), (2, 'three', 'four');",
  2434  			"set @Commit1 = '';",
  2435  			"call dolt_commit_hash_out(@Commit1, '-am', 'inserting two rows into table t');",
  2436  
  2437  			"insert into t values (3, 'five', 'six');",
  2438  			"delete from t where pk = 2",
  2439  			"update t set c2 = '100' where pk = 1",
  2440  		},
  2441  		Assertions: []queries.ScriptTestAssertion{
  2442  			{
  2443  				Query:    "SELECT * from dolt_diff_summary(@Commit1, 'WORKING', 't')",
  2444  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2445  			},
  2446  			{
  2447  				Query:    "SELECT * from dolt_diff_summary('STAGED', 'WORKING', 't')",
  2448  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2449  			},
  2450  			{
  2451  				Query:    "SELECT * from dolt_diff_summary('STAGED..WORKING', 't')",
  2452  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2453  			},
  2454  			{
  2455  				Query:    "SELECT * from dolt_diff_summary('WORKING', 'STAGED', 't')",
  2456  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2457  			},
  2458  			{
  2459  				Query:    "SELECT * from dolt_diff_summary('WORKING', 'WORKING', 't')",
  2460  				Expected: []sql.Row{},
  2461  			},
  2462  			{
  2463  				Query:    "SELECT * from dolt_diff_summary('WORKING..WORKING', 't')",
  2464  				Expected: []sql.Row{},
  2465  			},
  2466  			{
  2467  				Query:    "SELECT * from dolt_diff_summary('STAGED', 'STAGED', 't')",
  2468  				Expected: []sql.Row{},
  2469  			},
  2470  			{
  2471  				Query:            "call dolt_add('.')",
  2472  				SkipResultsCheck: true,
  2473  			},
  2474  			{
  2475  				Query:    "SELECT * from dolt_diff_summary('WORKING', 'STAGED', 't')",
  2476  				Expected: []sql.Row{},
  2477  			},
  2478  			{
  2479  				Query:    "SELECT * from dolt_diff_summary('HEAD', 'STAGED', 't')",
  2480  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2481  			},
  2482  		},
  2483  	},
  2484  	{
  2485  		Name: "diff with branch refs",
  2486  		SetUpScript: []string{
  2487  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  2488  			"call dolt_add('.')",
  2489  			"set @Commit1 = '';",
  2490  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
  2491  
  2492  			"insert into t values(1, 'one', 'two');",
  2493  			"set @Commit2 = '';",
  2494  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting row 1 into t in main');",
  2495  
  2496  			"CALL DOLT_checkout('-b', 'branch1');",
  2497  			"alter table t drop column c2;",
  2498  			"set @Commit3 = '';",
  2499  			"call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c2 in branch1');",
  2500  
  2501  			"delete from t where pk=1;",
  2502  			"set @Commit4 = '';",
  2503  			"call dolt_commit_hash_out(@Commit4, '-am', 'deleting row 1 in branch1');",
  2504  
  2505  			"insert into t values (2, 'two');",
  2506  			"set @Commit5 = '';",
  2507  			"call dolt_commit_hash_out(@Commit5, '-am', 'inserting row 2 in branch1');",
  2508  
  2509  			"CALL DOLT_checkout('main');",
  2510  			"insert into t values (2, 'two', 'three');",
  2511  			"set @Commit6 = '';",
  2512  			"call dolt_commit_hash_out(@Commit6, '-am', 'inserting row 2 in main');",
  2513  
  2514  			"create table newtable (pk int primary key);",
  2515  			"insert into newtable values (1), (2);",
  2516  			"set @Commit7 = '';",
  2517  			"call dolt_commit_hash_out(@Commit7, '-Am', 'new table newtable');",
  2518  		},
  2519  		Assertions: []queries.ScriptTestAssertion{
  2520  			{
  2521  				Query:    "SELECT * from dolt_diff_summary('main', 'branch1', 't');",
  2522  				Expected: []sql.Row{{"t", "t", "modified", true, true}},
  2523  			},
  2524  			{
  2525  				Query:    "SELECT * from dolt_diff_summary('main..branch1', 't');",
  2526  				Expected: []sql.Row{{"t", "t", "modified", true, true}},
  2527  			},
  2528  			{
  2529  				Query: "SELECT * from dolt_diff_summary('main', 'branch1');",
  2530  				Expected: []sql.Row{
  2531  					{"t", "t", "modified", true, true},
  2532  					{"newtable", "", "dropped", true, true},
  2533  				},
  2534  			},
  2535  			{
  2536  				Query: "SELECT * from dolt_diff_summary('main..branch1');",
  2537  				Expected: []sql.Row{
  2538  					{"t", "t", "modified", true, true},
  2539  					{"newtable", "", "dropped", true, true},
  2540  				},
  2541  			},
  2542  			{
  2543  				Query:    "SELECT * from dolt_diff_summary('branch1', 'main', 't');",
  2544  				Expected: []sql.Row{{"t", "t", "modified", true, true}},
  2545  			},
  2546  			{
  2547  				Query:    "SELECT * from dolt_diff_summary('branch1..main', 't');",
  2548  				Expected: []sql.Row{{"t", "t", "modified", true, true}},
  2549  			},
  2550  			{
  2551  				Query:    "SELECT * from dolt_diff_summary('main~2', 'branch1', 't');",
  2552  				Expected: []sql.Row{{"t", "t", "modified", true, true}},
  2553  			},
  2554  			{
  2555  				Query:    "SELECT * from dolt_diff_summary('main~2..branch1', 't');",
  2556  				Expected: []sql.Row{{"t", "t", "modified", true, true}},
  2557  			},
  2558  
  2559  			// Three dot
  2560  			{
  2561  				Query:    "SELECT * from dolt_diff_summary('main...branch1', 't');",
  2562  				Expected: []sql.Row{{"t", "t", "modified", true, true}},
  2563  			},
  2564  			{
  2565  				Query:    "SELECT * from dolt_diff_summary('main...branch1');",
  2566  				Expected: []sql.Row{{"t", "t", "modified", true, true}},
  2567  			},
  2568  			{
  2569  				Query:    "SELECT * from dolt_diff_summary('branch1...main', 't');",
  2570  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2571  			},
  2572  			{
  2573  				Query: "SELECT * from dolt_diff_summary('branch1...main');",
  2574  				Expected: []sql.Row{
  2575  					{"t", "t", "modified", true, false},
  2576  					{"", "newtable", "added", true, true},
  2577  				},
  2578  			},
  2579  			{
  2580  				Query:    "SELECT * from dolt_diff_summary('branch1...main^');",
  2581  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2582  			},
  2583  			{
  2584  				Query:    "SELECT * from dolt_diff_summary('branch1...main', 'newtable');",
  2585  				Expected: []sql.Row{{"", "newtable", "added", true, true}},
  2586  			},
  2587  			{
  2588  				Query:    "SELECT * from dolt_diff_summary('main...main', 'newtable');",
  2589  				Expected: []sql.Row{},
  2590  			},
  2591  		},
  2592  	},
  2593  	{
  2594  		Name: "schema modification: drop and add column",
  2595  		SetUpScript: []string{
  2596  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  2597  			"call dolt_add('.');",
  2598  			"insert into t values (1, 'one', 'two'), (2, 'two', 'three');",
  2599  			"set @Commit1 = '';",
  2600  			"call dolt_commit_hash_out(@Commit1, '-am', 'inserting row 1, 2 into t');",
  2601  
  2602  			// drop 1 column
  2603  			"alter table t drop column c2;",
  2604  			"set @Commit2 = '';",
  2605  			"call dolt_commit_hash_out(@Commit2, '-am', 'dropping column c2');",
  2606  
  2607  			// add 1 row
  2608  			"insert into t values (3, 'three');",
  2609  			"set @Commit3 = '';",
  2610  			"call dolt_commit_hash_out(@Commit3, '-am', 'inserting row 3');",
  2611  
  2612  			// add 1 column
  2613  			"alter table t add column c2 varchar(20);",
  2614  			"set @Commit4 = '';",
  2615  			"call dolt_commit_hash_out(@Commit4, '-am', 'adding column c2');",
  2616  
  2617  			// add 1 row and update
  2618  			"insert into t values (4, 'four', 'five');",
  2619  			"update t set c2='foo' where pk=1;",
  2620  			"set @Commit5 = '';",
  2621  			"call dolt_commit_hash_out(@Commit5, '-am', 'inserting and updating data');",
  2622  		},
  2623  		Assertions: []queries.ScriptTestAssertion{
  2624  			{
  2625  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit2, 't');",
  2626  				Expected: []sql.Row{{"t", "t", "modified", true, true}},
  2627  			},
  2628  			{
  2629  				Query:    "SELECT * from dolt_diff_summary(@Commit2, @Commit3, 't');",
  2630  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2631  			},
  2632  			{
  2633  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit3, 't');",
  2634  				Expected: []sql.Row{{"t", "t", "modified", true, true}},
  2635  			},
  2636  			{
  2637  				Query:    "SELECT * from dolt_diff_summary(@Commit3, @Commit4, 't');",
  2638  				Expected: []sql.Row{{"t", "t", "modified", false, true}},
  2639  			},
  2640  			{
  2641  				Query:    "SELECT * from dolt_diff_summary(@Commit3, @Commit5, 't');",
  2642  				Expected: []sql.Row{{"t", "t", "modified", true, true}},
  2643  			},
  2644  			{
  2645  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit5, 't');",
  2646  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2647  			},
  2648  		},
  2649  	},
  2650  	{
  2651  		Name: "schema modification: rename columns",
  2652  		SetUpScript: []string{
  2653  			"create table t (pk int primary key, c1 varchar(20), c2 int);",
  2654  			"call dolt_add('.')",
  2655  			"set @Commit1 = '';",
  2656  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
  2657  
  2658  			// add rows
  2659  			"insert into t values(1, 'one', -1), (2, 'two', -2);",
  2660  			"set @Commit2 = '';",
  2661  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');",
  2662  
  2663  			// rename column
  2664  			"alter table t rename column c2 to c3;",
  2665  			"set @Commit3 = '';",
  2666  			"call dolt_commit_hash_out(@Commit3, '-am', 'renaming column c2 to c3');",
  2667  
  2668  			// add row and update
  2669  			"insert into t values (3, 'three', -3);",
  2670  			"update t set c3=1 where pk=1;",
  2671  			"set @Commit4 = '';",
  2672  			"call dolt_commit_hash_out(@Commit4, '-am', 'inserting and updating data');",
  2673  
  2674  			// rename column and add row
  2675  			"alter table t rename column c3 to c2;",
  2676  			"insert into t values (4, 'four', -4);",
  2677  			"set @Commit5 = '';",
  2678  			"call dolt_commit_hash_out(@Commit5, '-am', 'renaming column c3 to c2, and inserting data');",
  2679  		},
  2680  		Assertions: []queries.ScriptTestAssertion{
  2681  			{
  2682  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit2, 't');",
  2683  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2684  			},
  2685  			{
  2686  				Query:    "SELECT * from dolt_diff_summary(@Commit2, @Commit3, 't');",
  2687  				Expected: []sql.Row{{"t", "t", "modified", false, true}},
  2688  			},
  2689  			{
  2690  				Query:    "SELECT * from dolt_diff_summary(@Commit3, @Commit4, 't');",
  2691  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2692  			},
  2693  			{
  2694  				Query:    "SELECT * from dolt_diff_summary(@Commit4, @Commit5, 't');",
  2695  				Expected: []sql.Row{{"t", "t", "modified", true, true}},
  2696  			},
  2697  			{
  2698  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit5, 't');",
  2699  				Expected: []sql.Row{{"t", "t", "modified", true, false}},
  2700  			},
  2701  		},
  2702  	},
  2703  
  2704  	{
  2705  		Name: "new table",
  2706  		SetUpScript: []string{
  2707  			"create table t1 (a int primary key, b int)",
  2708  		},
  2709  		Assertions: []queries.ScriptTestAssertion{
  2710  			{
  2711  				Query:    "select * from dolt_diff_summary('HEAD', 'WORKING')",
  2712  				Expected: []sql.Row{{"", "t1", "added", false, true}},
  2713  			},
  2714  			{
  2715  				Query:    "select * from dolt_diff_summary('WORKING', 'HEAD')",
  2716  				Expected: []sql.Row{{"t1", "", "dropped", false, true}},
  2717  			},
  2718  			{
  2719  				Query:            "insert into t1 values (1,2)",
  2720  				SkipResultsCheck: true,
  2721  			},
  2722  			{
  2723  				Query:    "select * from dolt_diff_summary('HEAD', 'WORKING', 't1')",
  2724  				Expected: []sql.Row{{"", "t1", "added", true, true}},
  2725  			},
  2726  			{
  2727  				Query:    "select * from dolt_diff_summary('WORKING', 'HEAD', 't1')",
  2728  				Expected: []sql.Row{{"t1", "", "dropped", true, true}},
  2729  			},
  2730  		},
  2731  	},
  2732  
  2733  	{
  2734  		Name: "dropped table",
  2735  		SetUpScript: []string{
  2736  			"create table t1 (a int primary key, b int)",
  2737  			"call dolt_add('.')",
  2738  			"insert into t1 values (1,2)",
  2739  			"call dolt_commit('-am', 'new table')",
  2740  			"drop table t1",
  2741  			"call dolt_commit('-am', 'dropped table')",
  2742  		},
  2743  		Assertions: []queries.ScriptTestAssertion{
  2744  			{
  2745  				Query:    "select * from dolt_diff_summary('HEAD~', 'HEAD', 't1')",
  2746  				Expected: []sql.Row{{"t1", "", "dropped", true, true}},
  2747  			},
  2748  			{
  2749  				Query:    "select * from dolt_diff_summary('HEAD', 'HEAD~', 't1')",
  2750  				Expected: []sql.Row{{"", "t1", "added", true, true}},
  2751  			},
  2752  		},
  2753  	},
  2754  
  2755  	{
  2756  		Name: "renamed table",
  2757  		SetUpScript: []string{
  2758  			"create table t1 (a int primary key, b int)",
  2759  			"call dolt_add('.')",
  2760  			"insert into t1 values (1,2)",
  2761  			"call dolt_commit('-am', 'new table')",
  2762  			"alter table t1 rename to t2",
  2763  			"call dolt_add('.')",
  2764  			"insert into t2 values (3,4)",
  2765  			"call dolt_commit('-am', 'renamed table')",
  2766  		},
  2767  		Assertions: []queries.ScriptTestAssertion{
  2768  			{
  2769  				Query:    "select * from dolt_diff_summary('HEAD~', 'HEAD', 't2')",
  2770  				Expected: []sql.Row{{"t1", "t2", "renamed", true, true}},
  2771  			},
  2772  			{
  2773  				Query:    "select * from dolt_diff_summary('HEAD~..HEAD', 't2')",
  2774  				Expected: []sql.Row{{"t1", "t2", "renamed", true, true}},
  2775  			},
  2776  			{
  2777  				Query:    "select * from dolt_diff_summary('HEAD~', 'HEAD')",
  2778  				Expected: []sql.Row{{"t1", "t2", "renamed", true, true}},
  2779  			},
  2780  			{
  2781  				Query:    "select * from dolt_diff_summary('HEAD~..HEAD')",
  2782  				Expected: []sql.Row{{"t1", "t2", "renamed", true, true}},
  2783  			},
  2784  			{
  2785  				// Old table name can be matched as well
  2786  				Query:    "select * from dolt_diff_summary('HEAD~', 'HEAD', 't1')",
  2787  				Expected: []sql.Row{{"t1", "t2", "renamed", true, true}},
  2788  			},
  2789  			{
  2790  				// Old table name can be matched as well
  2791  				Query:    "select * from dolt_diff_summary('HEAD~..HEAD', 't1')",
  2792  				Expected: []sql.Row{{"t1", "t2", "renamed", true, true}},
  2793  			},
  2794  		},
  2795  	},
  2796  	{
  2797  		Name: "foreign key change",
  2798  		SetUpScript: []string{
  2799  			"create table test (id int primary key);",
  2800  			"INSERT INTO test values (1), (2);",
  2801  			"set @Commit1 = '';",
  2802  			"CALL dolt_commit_hash_out(@Commit1, '-Am', 'create table test');",
  2803  
  2804  			"create table test2 (pk int primary key, test_id int);",
  2805  			"alter table test2 add constraint fk_test_id foreign key (test_id) references test(id);",
  2806  			"insert into test2 values (1, 1);",
  2807  			"set @Commit2 = '';",
  2808  			"CALL dolt_commit_hash_out(@Commit2, '-Am', 'table with foreign key and row');",
  2809  
  2810  			"alter table test2 drop foreign key fk_test_id;",
  2811  		},
  2812  		Assertions: []queries.ScriptTestAssertion{
  2813  			{
  2814  				Query:    "SELECT * from dolt_diff_summary(@Commit1, @Commit2);",
  2815  				Expected: []sql.Row{{"", "test2", "added", true, true}},
  2816  			},
  2817  			{
  2818  				Query:    "SELECT * from dolt_diff_summary('HEAD', 'WORKING');",
  2819  				Expected: []sql.Row{{"test2", "test2", "modified", false, true}},
  2820  			},
  2821  			{
  2822  				Query:    "SELECT * from dolt_diff_summary(@Commit1, 'WORKING');",
  2823  				Expected: []sql.Row{{"", "test2", "added", true, true}},
  2824  			},
  2825  		},
  2826  	},
  2827  	{
  2828  		Name: "add multiple columns, then set and unset a value. Should not show a diff",
  2829  		SetUpScript: []string{
  2830  			"CREATE table t (pk int primary key);",
  2831  			"insert into t values (1);",
  2832  			"CALL DOLT_ADD('.');",
  2833  			"CALL DOLT_COMMIT('-am', 'setup');",
  2834  			"alter table t add column col1 int;",
  2835  			"alter table t add column col2 int;",
  2836  			"CALL DOLT_ADD('.');",
  2837  			"CALL DOLT_COMMIT('-am', 'add columns');",
  2838  			"UPDATE t set col1 = 1 where pk = 1;",
  2839  			"UPDATE t set col1 = null where pk = 1;",
  2840  			"CALL DOLT_COMMIT('--allow-empty', '-am', 'fix short tuple');",
  2841  		},
  2842  		Assertions: []queries.ScriptTestAssertion{
  2843  			{
  2844  				Query:    "SELECT * from dolt_diff_summary('HEAD~2', 'HEAD');",
  2845  				Expected: []sql.Row{{"t", "t", "modified", false, true}},
  2846  			},
  2847  			{
  2848  				Query:    "SELECT * from dolt_diff_summary('HEAD~', 'HEAD');",
  2849  				Expected: []sql.Row{},
  2850  			},
  2851  		},
  2852  	},
  2853  	{
  2854  		Name: "pk set change should throw an error for 3 argument dolt_diff_summary",
  2855  		SetUpScript: []string{
  2856  			"CREATE table t (pk int primary key);",
  2857  			"INSERT INTO t values (1);",
  2858  			"CALL DOLT_COMMIT('-Am', 'table with row');",
  2859  			"ALTER TABLE t ADD col1 int not null default 0;",
  2860  			"ALTER TABLE t drop primary key;",
  2861  			"ALTER TABLE t add primary key (pk, col1);",
  2862  			"CALL DOLT_COMMIT('-am', 'add secondary column with primary key');",
  2863  		},
  2864  		Assertions: []queries.ScriptTestAssertion{
  2865  			{
  2866  				Query:          "SELECT * from dolt_diff_summary('HEAD~', 'HEAD', 't');",
  2867  				ExpectedErrStr: "failed to compute diff summary for table t: primary key set changed",
  2868  			},
  2869  		},
  2870  	},
  2871  	{
  2872  		Name: "pk set change should report warning for 2 argument dolt_diff_summary",
  2873  		SetUpScript: []string{
  2874  			"CREATE table t (pk int primary key);",
  2875  			"INSERT INTO t values (1);",
  2876  			"CREATE table t2 (pk int primary key);",
  2877  			"INSERT INTO t2 values (2);",
  2878  			"CALL DOLT_COMMIT('-Am', 'multiple tables');",
  2879  			"ALTER TABLE t ADD col1 int not null default 0;",
  2880  			"ALTER TABLE t drop primary key;",
  2881  			"ALTER TABLE t add primary key (pk, col1);",
  2882  			"INSERT INTO t2 values (3), (4), (5);",
  2883  			"CALL DOLT_COMMIT('-am', 'add secondary column with primary key to t');",
  2884  		},
  2885  		Assertions: []queries.ScriptTestAssertion{
  2886  			{
  2887  				Query: "SELECT * from dolt_diff_summary('HEAD~', 'HEAD')",
  2888  				Expected: []sql.Row{
  2889  					{"t2", "t2", "modified", true, false},
  2890  				},
  2891  				ExpectedWarning:       dtables.PrimaryKeyChangeWarningCode,
  2892  				ExpectedWarningsCount: 1,
  2893  			},
  2894  		},
  2895  	},
  2896  }
  2897  
  2898  var PatchTableFunctionScriptTests = []queries.ScriptTest{
  2899  	{
  2900  		Name: "invalid arguments",
  2901  		SetUpScript: []string{
  2902  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  2903  			"call dolt_add('.')",
  2904  			"set @Commit1 = '';",
  2905  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
  2906  
  2907  			"insert into t values(1, 'one', 'two'), (2, 'two', 'three');",
  2908  			"set @Commit2 = '';",
  2909  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');",
  2910  		},
  2911  		Assertions: []queries.ScriptTestAssertion{
  2912  			{
  2913  				Query:       "SELECT * from dolt_patch();",
  2914  				ExpectedErr: sql.ErrInvalidArgumentNumber,
  2915  			},
  2916  			{
  2917  				Query:       "SELECT * from dolt_patch('t');",
  2918  				ExpectedErr: sql.ErrInvalidArgumentNumber,
  2919  			},
  2920  			{
  2921  				Query:       "SELECT * from dolt_patch('t', @Commit1, @Commit2, 'extra');",
  2922  				ExpectedErr: sql.ErrInvalidArgumentNumber,
  2923  			},
  2924  			{
  2925  				Query:       "SELECT * from dolt_patch(null, null, null);",
  2926  				ExpectedErr: sql.ErrInvalidArgumentDetails,
  2927  			},
  2928  			{
  2929  				Query:       "SELECT * from dolt_patch(123, @Commit1, @Commit2);",
  2930  				ExpectedErr: sql.ErrInvalidArgumentDetails,
  2931  			},
  2932  			{
  2933  				Query:       "SELECT * from dolt_patch('t', 123, @Commit2);",
  2934  				ExpectedErr: sql.ErrInvalidArgumentDetails,
  2935  			},
  2936  			{
  2937  				Query:       "SELECT * from dolt_patch('t', @Commit1, 123);",
  2938  				ExpectedErr: sql.ErrInvalidArgumentDetails,
  2939  			},
  2940  			{
  2941  				Query:          "SELECT * from dolt_patch('fake-branch', @Commit2, 't');",
  2942  				ExpectedErrStr: "branch not found: fake-branch",
  2943  			},
  2944  			{
  2945  				Query:          "SELECT * from dolt_patch('fake-branch..main', 't');",
  2946  				ExpectedErrStr: "branch not found: fake-branch",
  2947  			},
  2948  			{
  2949  				Query:          "SELECT * from dolt_patch(@Commit1, 'fake-branch', 't');",
  2950  				ExpectedErrStr: "branch not found: fake-branch",
  2951  			},
  2952  			{
  2953  				Query:          "SELECT * from dolt_patch('main..fake-branch', 't');",
  2954  				ExpectedErrStr: "branch not found: fake-branch",
  2955  			},
  2956  			{
  2957  				Query:       "SELECT * from dolt_patch(@Commit1, @Commit2, 'doesnotexist');",
  2958  				ExpectedErr: sql.ErrTableNotFound,
  2959  			},
  2960  			{
  2961  				Query:       "SELECT * from dolt_patch('main^..main', 'doesnotexist');",
  2962  				ExpectedErr: sql.ErrTableNotFound,
  2963  			},
  2964  			{
  2965  				Query:       "SELECT * from dolt_patch(@Commit1, concat('fake', '-', 'branch'), 't');",
  2966  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
  2967  			},
  2968  			{
  2969  				Query:       "SELECT * from dolt_patch(hashof('main'), @Commit2, 't');",
  2970  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
  2971  			},
  2972  			{
  2973  				Query:       "SELECT * from dolt_patch(@Commit1, @Commit2, LOWER('T'));",
  2974  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
  2975  			},
  2976  			{
  2977  				Query:       "SELECT * from dolt_patch('main..main~', LOWER('T'));",
  2978  				ExpectedErr: sqle.ErrInvalidNonLiteralArgument,
  2979  			},
  2980  		},
  2981  	},
  2982  	{
  2983  		Name: "basic case with single table",
  2984  		SetUpScript: []string{
  2985  			"set @Commit0 = HashOf('HEAD');",
  2986  			"set @Commit1 = '';",
  2987  			"call dolt_commit_hash_out(@Commit1, '--allow-empty', '-m', 'creating table t');",
  2988  
  2989  			// create table t only
  2990  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  2991  			"call dolt_add('.')",
  2992  			"set @Commit2 = '';",
  2993  			"call dolt_commit_hash_out(@Commit2, '-am', 'creating table t');",
  2994  
  2995  			// insert 1 row into t
  2996  			"insert into t values(1, 'one', 'two');",
  2997  			"set @Commit3 = '';",
  2998  			"call dolt_commit_hash_out(@Commit3, '-am', 'inserting 1 into table t');",
  2999  
  3000  			// insert 2 rows into t and update two cells
  3001  			"insert into t values(2, 'two', 'three'), (3, 'three', 'four');",
  3002  			"update t set c1='uno', c2='dos' where pk=1;",
  3003  			"set @Commit4 = '';",
  3004  			"call dolt_commit_hash_out(@Commit4, '-am', 'inserting 2 into table t');",
  3005  
  3006  			// drop table t only
  3007  			"drop table t;",
  3008  			"set @Commit5 = '';",
  3009  			"call dolt_commit_hash_out(@Commit5, '-am', 'drop table t');",
  3010  		},
  3011  		Assertions: []queries.ScriptTestAssertion{
  3012  			{
  3013  				// table is added, no data diff, result is empty
  3014  				Query:    "SELECT * from dolt_patch(@Commit1, @Commit2, 't') WHERE diff_type = 'data';",
  3015  				Expected: []sql.Row{},
  3016  			},
  3017  			{
  3018  				Query:    "SELECT statement_order, table_name, statement from dolt_patch(@Commit1, @Commit2, 't') WHERE diff_type = 'schema';",
  3019  				Expected: []sql.Row{{1, "t", "CREATE TABLE `t` (\n  `pk` int NOT NULL,\n  `c1` varchar(20),\n  `c2` varchar(20),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"}},
  3020  			},
  3021  			{
  3022  				Query:    "SELECT statement_order, table_name, diff_type, statement from dolt_patch(@Commit2, @Commit3, 't');",
  3023  				Expected: []sql.Row{{1, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (1,'one','two');"}},
  3024  			},
  3025  			{
  3026  				Query: "SELECT statement_order, table_name, diff_type, statement from dolt_patch(@Commit3, @Commit4, 't');",
  3027  				Expected: []sql.Row{
  3028  					{1, "t", "data", "UPDATE `t` SET `c1`='uno',`c2`='dos' WHERE `pk`=1;"},
  3029  					{2, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (2,'two','three');"},
  3030  					{3, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (3,'three','four');"},
  3031  				},
  3032  			},
  3033  			{
  3034  				// change from and to commits
  3035  				Query: "SELECT statement_order, table_name, diff_type, statement from dolt_patch(@Commit4, @Commit3, 't');",
  3036  				Expected: []sql.Row{
  3037  					{1, "t", "data", "UPDATE `t` SET `c1`='one',`c2`='two' WHERE `pk`=1;"},
  3038  					{2, "t", "data", "DELETE FROM `t` WHERE `pk`=2;"},
  3039  					{3, "t", "data", "DELETE FROM `t` WHERE `pk`=3;"},
  3040  				},
  3041  			},
  3042  			{
  3043  				// table is dropped
  3044  				Query:    "SELECT statement_order, table_name, diff_type, statement from dolt_patch(@Commit4, @Commit5, 't');",
  3045  				Expected: []sql.Row{{1, "t", "schema", "DROP TABLE `t`;"}},
  3046  			},
  3047  			{
  3048  				Query: "SELECT statement_order, table_name, diff_type, statement from dolt_patch(@Commit1, @Commit4, 't');",
  3049  				Expected: []sql.Row{
  3050  					{1, "t", "schema", "CREATE TABLE `t` (\n  `pk` int NOT NULL,\n  `c1` varchar(20),\n  `c2` varchar(20),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  3051  					{2, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (1,'uno','dos');"},
  3052  					{3, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (2,'two','three');"},
  3053  					{4, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (3,'three','four');"},
  3054  				},
  3055  			},
  3056  			{
  3057  				Query:       "SELECT * from dolt_patch(@Commit1, @Commit5, 't');",
  3058  				ExpectedErr: sql.ErrTableNotFound,
  3059  			},
  3060  		},
  3061  	},
  3062  	{
  3063  		// https://github.com/dolthub/dolt/issues/6350
  3064  		Name: "binary data in patch statements is hex encoded",
  3065  		SetUpScript: []string{
  3066  			"create table t (pk varbinary(16) primary key, c1  binary(16));",
  3067  			"insert into t values (0x42, NULL);",
  3068  			"call dolt_commit('-Am', 'new table with binary pk');",
  3069  			"update t set c1 = 0xeeee where pk = 0x42;",
  3070  			"insert into t values (0x012345, NULL), (0x054321, binary 'efg_!4');",
  3071  			"call dolt_commit('-am', 'more rows');",
  3072  		},
  3073  		Assertions: []queries.ScriptTestAssertion{
  3074  			{
  3075  				Query: "select statement from dolt_patch('HEAD~', 'HEAD', 't');",
  3076  				Expected: []sql.Row{
  3077  					{"INSERT INTO `t` (`pk`,`c1`) VALUES (0x012345,NULL);"},
  3078  					{"INSERT INTO `t` (`pk`,`c1`) VALUES (0x054321,0x6566675f213400000000000000000000);"},
  3079  					{"UPDATE `t` SET `c1`=0xeeee0000000000000000000000000000 WHERE `pk`=0x42;"},
  3080  				},
  3081  			},
  3082  		},
  3083  	},
  3084  	{
  3085  		Name: "basic case with multiple tables",
  3086  		SetUpScript: []string{
  3087  			"set @Commit0 = HashOf('HEAD');",
  3088  
  3089  			// add table t with 1 row
  3090  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  3091  			"insert into t values(1, 'one', 'two');",
  3092  			"call dolt_add('.')",
  3093  			"set @Commit1 = '';",
  3094  			"call dolt_commit_hash_out(@Commit1, '-am', 'inserting into table t');",
  3095  
  3096  			// add table t2 with 1 row
  3097  			"create table t2 (pk int primary key, c1 varchar(20), c2 varchar(20));",
  3098  			"insert into t2 values(100, 'hundred', 'hundert');",
  3099  			"call dolt_add('.')",
  3100  			"set @Commit2 = '';",
  3101  			"call dolt_commit_hash_out(@Commit2, '-am', 'inserting into table t2');",
  3102  
  3103  			// changes on both tables
  3104  			"insert into t values(2, 'two', 'three'), (3, 'three', 'four'), (4, 'four', 'five');",
  3105  			"update t set c1='uno', c2='dos' where pk=1;",
  3106  			"insert into t2 values(101, 'hundred one', 'one');",
  3107  			"set @Commit3 = '';",
  3108  			"call dolt_commit_hash_out(@Commit3, '-am', 'inserting into table t');",
  3109  
  3110  			// changes on both tables
  3111  			"delete from t where c2 = 'four';",
  3112  			"update t2 set c2='zero' where pk=100;",
  3113  			"set @Commit4 = '';",
  3114  			"call dolt_commit_hash_out(@Commit4, '-am', 'inserting into table t');",
  3115  
  3116  			// create keyless table
  3117  			"create table keyless (id int);",
  3118  		},
  3119  		Assertions: []queries.ScriptTestAssertion{
  3120  			{
  3121  				Query: "SELECT statement_order, table_name, diff_type, statement from dolt_patch(@Commit0, @Commit1);",
  3122  				Expected: []sql.Row{
  3123  					{1, "t", "schema", "CREATE TABLE `t` (\n  `pk` int NOT NULL,\n  `c1` varchar(20),\n  `c2` varchar(20),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  3124  					{2, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (1,'one','two');"},
  3125  				},
  3126  			},
  3127  			{
  3128  				Query: "SELECT statement_order, table_name, diff_type, statement from dolt_patch(@Commit1, @Commit2);",
  3129  				Expected: []sql.Row{
  3130  					{1, "t2", "schema", "CREATE TABLE `t2` (\n  `pk` int NOT NULL,\n  `c1` varchar(20),\n  `c2` varchar(20),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  3131  					{2, "t2", "data", "INSERT INTO `t2` (`pk`,`c1`,`c2`) VALUES (100,'hundred','hundert');"},
  3132  				},
  3133  			},
  3134  			{
  3135  				Query: "SELECT statement_order, table_name, diff_type, statement from dolt_patch(@Commit2, @Commit3);",
  3136  				Expected: []sql.Row{
  3137  					{1, "t", "data", "UPDATE `t` SET `c1`='uno',`c2`='dos' WHERE `pk`=1;"},
  3138  					{2, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (2,'two','three');"},
  3139  					{3, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (3,'three','four');"},
  3140  					{4, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (4,'four','five');"},
  3141  					{5, "t2", "data", "INSERT INTO `t2` (`pk`,`c1`,`c2`) VALUES (101,'hundred one','one');"},
  3142  				},
  3143  			},
  3144  			{
  3145  				Query: "SELECT statement_order, table_name, diff_type, statement from dolt_patch(@Commit3, @Commit4);",
  3146  				Expected: []sql.Row{
  3147  					{1, "t", "data", "DELETE FROM `t` WHERE `pk`=3;"},
  3148  					{2, "t2", "data", "UPDATE `t2` SET `c2`='zero' WHERE `pk`=100;"},
  3149  				},
  3150  			},
  3151  			{
  3152  				Query: "SELECT statement_order, table_name, diff_type, statement from dolt_patch(@Commit4, @Commit2);",
  3153  				Expected: []sql.Row{
  3154  					{1, "t", "data", "UPDATE `t` SET `c1`='one',`c2`='two' WHERE `pk`=1;"},
  3155  					{2, "t", "data", "DELETE FROM `t` WHERE `pk`=2;"},
  3156  					{3, "t", "data", "DELETE FROM `t` WHERE `pk`=4;"},
  3157  					{4, "t2", "data", "UPDATE `t2` SET `c2`='hundert' WHERE `pk`=100;"},
  3158  					{5, "t2", "data", "DELETE FROM `t2` WHERE `pk`=101;"},
  3159  				},
  3160  			},
  3161  			{
  3162  				Query: "SELECT statement_order, table_name, diff_type, statement from dolt_patch(@Commit3, 'WORKING');",
  3163  				Expected: []sql.Row{
  3164  					{1, "keyless", "schema", "CREATE TABLE `keyless` (\n  `id` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  3165  					{2, "t", "data", "DELETE FROM `t` WHERE `pk`=3;"},
  3166  					{3, "t2", "data", "UPDATE `t2` SET `c2`='zero' WHERE `pk`=100;"},
  3167  				},
  3168  			},
  3169  		},
  3170  	},
  3171  	{
  3172  		Name: "using WORKING and STAGED refs on RENAME, DROP and ADD column",
  3173  		SetUpScript: []string{
  3174  			"set @Commit0 = HashOf('HEAD');",
  3175  			"create table t (pk int primary key, c1 int, c2 int, c3 int, c4 int, c5 int comment 'tag:5');",
  3176  			"insert into t values (0,1,2,3,4,5), (1,1,2,3,4,5);",
  3177  			"call dolt_commit('-Am', 'inserting two rows into table t');",
  3178  			"alter table t rename column c1 to c0;",
  3179  			"alter table t drop column c4;",
  3180  			"alter table t add c6 bigint;",
  3181  		},
  3182  		Assertions: []queries.ScriptTestAssertion{
  3183  			{
  3184  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('HEAD', 'WORKING', 't')",
  3185  				Expected: []sql.Row{
  3186  					{1, "t", "schema", "ALTER TABLE `t` RENAME COLUMN `c1` TO `c0`;"},
  3187  					{2, "t", "schema", "ALTER TABLE `t` DROP `c4`;"},
  3188  					{3, "t", "schema", "ALTER TABLE `t` ADD `c6` bigint;"},
  3189  					// NOTE: These two update statements aren't technically needed, but we can't tell that from the diff.
  3190  					//       Because the rows were altered on disk due to the `drop column` statement above, these rows
  3191  					//       really did change on disk and we can't currently safely tell that it was ONLY the column
  3192  					//       rename and that there weren't other updates to that column.
  3193  					{4, "t", "data", "UPDATE `t` SET `c0`=1 WHERE `pk`=0;"},
  3194  					{5, "t", "data", "UPDATE `t` SET `c0`=1 WHERE `pk`=1;"},
  3195  				},
  3196  			},
  3197  			{
  3198  				Query: "SELECT * FROM dolt_patch('STAGED', 'WORKING', 't')",
  3199  				Expected: []sql.Row{
  3200  					{1, "STAGED", "WORKING", "t", "schema", "ALTER TABLE `t` RENAME COLUMN `c1` TO `c0`;"},
  3201  					{2, "STAGED", "WORKING", "t", "schema", "ALTER TABLE `t` DROP `c4`;"},
  3202  					{3, "STAGED", "WORKING", "t", "schema", "ALTER TABLE `t` ADD `c6` bigint;"},
  3203  					// NOTE: These two update statements aren't technically needed, but we can't tell that from the diff.
  3204  					//       Because the rows were altered on disk due to the `drop column` statement above, these rows
  3205  					//       really did change on disk and we can't currently safely tell that it was ONLY the column
  3206  					//       rename and that there weren't other updates to that column.
  3207  					{4, "STAGED", "WORKING", "t", "data", "UPDATE `t` SET `c0`=1 WHERE `pk`=0;"},
  3208  					{5, "STAGED", "WORKING", "t", "data", "UPDATE `t` SET `c0`=1 WHERE `pk`=1;"},
  3209  				},
  3210  			},
  3211  			{
  3212  				Query: "SELECT * FROM dolt_patch('STAGED..WORKING', 't')",
  3213  				Expected: []sql.Row{
  3214  					{1, "STAGED", "WORKING", "t", "schema", "ALTER TABLE `t` RENAME COLUMN `c1` TO `c0`;"},
  3215  					{2, "STAGED", "WORKING", "t", "schema", "ALTER TABLE `t` DROP `c4`;"},
  3216  					{3, "STAGED", "WORKING", "t", "schema", "ALTER TABLE `t` ADD `c6` bigint;"},
  3217  					// NOTE: These two update statements aren't technically needed, but we can't tell that from the diff.
  3218  					//       Because the rows were altered on disk due to the `drop column` statement above, these rows
  3219  					//       really did change on disk and we can't currently safely tell that it was ONLY the column
  3220  					//       rename and that there weren't other updates to that column.
  3221  					{4, "STAGED", "WORKING", "t", "data", "UPDATE `t` SET `c0`=1 WHERE `pk`=0;"},
  3222  					{5, "STAGED", "WORKING", "t", "data", "UPDATE `t` SET `c0`=1 WHERE `pk`=1;"},
  3223  				},
  3224  			},
  3225  			{
  3226  				Query: "SELECT * FROM dolt_patch('WORKING', 'STAGED', 't')",
  3227  				Expected: []sql.Row{
  3228  					{1, "WORKING", "STAGED", "t", "schema", "ALTER TABLE `t` RENAME COLUMN `c0` TO `c1`;"},
  3229  					{2, "WORKING", "STAGED", "t", "schema", "ALTER TABLE `t` DROP `c6`;"},
  3230  					{3, "WORKING", "STAGED", "t", "schema", "ALTER TABLE `t` ADD `c4` int;"},
  3231  					// NOTE: Setting c1 in these two update statements isn't technically needed, but we can't tell that
  3232  					//       from the diff. Because the rows were altered on disk due to the `drop column` statement above,
  3233  					//       these rows really did change on disk and we can't currently safely tell that it was ONLY the
  3234  					//       column rename and that there weren't other updates to that column.
  3235  					{4, "WORKING", "STAGED", "t", "data", "UPDATE `t` SET `c1`=1,`c4`=4 WHERE `pk`=0;"},
  3236  					{5, "WORKING", "STAGED", "t", "data", "UPDATE `t` SET `c1`=1,`c4`=4 WHERE `pk`=1;"},
  3237  				},
  3238  			},
  3239  			{
  3240  				Query:    "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('WORKING', 'WORKING', 't')",
  3241  				Expected: []sql.Row{},
  3242  			},
  3243  			{
  3244  				Query:    "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('WORKING..WORKING', 't')",
  3245  				Expected: []sql.Row{},
  3246  			},
  3247  			{
  3248  				Query:    "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('STAGED', 'STAGED', 't')",
  3249  				Expected: []sql.Row{},
  3250  			},
  3251  			{
  3252  				Query:            "call dolt_add('.')",
  3253  				SkipResultsCheck: true,
  3254  			},
  3255  			{
  3256  				Query:    "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('WORKING', 'STAGED', 't')",
  3257  				Expected: []sql.Row{},
  3258  			},
  3259  			{
  3260  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('HEAD', 'STAGED', 't')",
  3261  				Expected: []sql.Row{
  3262  					{1, "t", "schema", "ALTER TABLE `t` RENAME COLUMN `c1` TO `c0`;"},
  3263  					{2, "t", "schema", "ALTER TABLE `t` DROP `c4`;"},
  3264  					{3, "t", "schema", "ALTER TABLE `t` ADD `c6` bigint;"},
  3265  					{4, "t", "data", "UPDATE `t` SET `c0`=1 WHERE `pk`=0;"},
  3266  					{5, "t", "data", "UPDATE `t` SET `c0`=1 WHERE `pk`=1;"},
  3267  				},
  3268  			},
  3269  		},
  3270  	},
  3271  	{
  3272  		Name: "using branch refs different ways",
  3273  		SetUpScript: []string{
  3274  			"create table t (pk int primary key, c1 varchar(20), c2 varchar(20));",
  3275  			"call dolt_add('.')",
  3276  			"call dolt_commit('-am', 'creating table t');",
  3277  			"set @Commit1 = hashof('HEAD');",
  3278  
  3279  			"insert into t values(1, 'one', 'two');",
  3280  			"call dolt_commit('-am', 'inserting row 1 into t in main');",
  3281  			"set @Commit2 = hashof('HEAD');",
  3282  
  3283  			"CALL DOLT_checkout('-b', 'branch1');",
  3284  			"alter table t drop column c2;",
  3285  			"call dolt_commit('-am', 'dropping column c2 in branch1');",
  3286  			"set @Commit3 = hashof('HEAD');",
  3287  
  3288  			"delete from t where pk=1;",
  3289  			"call dolt_commit('-am', 'deleting row 1 in branch1');",
  3290  			"set @Commit4 = hashof('HEAD');",
  3291  
  3292  			"insert into t values (2, 'two');",
  3293  			"call dolt_commit('-am', 'inserting row 2 in branch1');",
  3294  			"set @Commit5 = hashof('HEAD');",
  3295  
  3296  			"CALL DOLT_checkout('main');",
  3297  			"insert into t values (2, 'two', 'three');",
  3298  			"call dolt_commit('-am', 'inserting row 2 in main');",
  3299  			"set @Commit6 = hashof('HEAD');",
  3300  
  3301  			"create table newtable (pk int primary key);",
  3302  			"insert into newtable values (1), (2);",
  3303  			"call dolt_commit('-Am', 'new table newtable');",
  3304  			"set @Commit7 = hashof('HEAD');",
  3305  		},
  3306  		Assertions: []queries.ScriptTestAssertion{
  3307  			{
  3308  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('main', 'branch1', 't');",
  3309  				Expected: []sql.Row{
  3310  					{1, "t", "schema", "ALTER TABLE `t` DROP `c2`;"},
  3311  					{2, "t", "data", "DELETE FROM `t` WHERE `pk`=1;"},
  3312  				},
  3313  			},
  3314  			{
  3315  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('main..branch1', 't');",
  3316  				Expected: []sql.Row{
  3317  					{1, "t", "schema", "ALTER TABLE `t` DROP `c2`;"},
  3318  					{2, "t", "data", "DELETE FROM `t` WHERE `pk`=1;"},
  3319  				},
  3320  			},
  3321  			{
  3322  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('main', 'branch1');",
  3323  				Expected: []sql.Row{
  3324  					{1, "newtable", "schema", "DROP TABLE `newtable`;"},
  3325  					{2, "t", "schema", "ALTER TABLE `t` DROP `c2`;"},
  3326  					{3, "t", "data", "DELETE FROM `t` WHERE `pk`=1;"},
  3327  				},
  3328  			},
  3329  			{
  3330  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('main..branch1');",
  3331  				Expected: []sql.Row{
  3332  					{1, "newtable", "schema", "DROP TABLE `newtable`;"},
  3333  					{2, "t", "schema", "ALTER TABLE `t` DROP `c2`;"},
  3334  					{3, "t", "data", "DELETE FROM `t` WHERE `pk`=1;"},
  3335  				},
  3336  			},
  3337  			{
  3338  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('branch1', 'main', 't');",
  3339  				Expected: []sql.Row{
  3340  					{1, "t", "schema", "ALTER TABLE `t` ADD `c2` varchar(20);"},
  3341  					{2, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (1,'one','two');"},
  3342  					{3, "t", "data", "UPDATE `t` SET `c2`='three' WHERE `pk`=2;"},
  3343  				},
  3344  			},
  3345  			{
  3346  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('branch1..main', 't');",
  3347  				Expected: []sql.Row{
  3348  					{1, "t", "schema", "ALTER TABLE `t` ADD `c2` varchar(20);"},
  3349  					{2, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (1,'one','two');"},
  3350  					{3, "t", "data", "UPDATE `t` SET `c2`='three' WHERE `pk`=2;"},
  3351  				},
  3352  			},
  3353  			{
  3354  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('main~2', 'branch1', 't');",
  3355  				Expected: []sql.Row{
  3356  					{1, "t", "schema", "ALTER TABLE `t` DROP `c2`;"},
  3357  					{2, "t", "data", "DELETE FROM `t` WHERE `pk`=1;"},
  3358  					{3, "t", "data", "INSERT INTO `t` (`pk`,`c1`) VALUES (2,'two');"},
  3359  				},
  3360  			},
  3361  			{
  3362  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('main~2..branch1', 't');",
  3363  				Expected: []sql.Row{
  3364  					{1, "t", "schema", "ALTER TABLE `t` DROP `c2`;"},
  3365  					{2, "t", "data", "DELETE FROM `t` WHERE `pk`=1;"},
  3366  					{3, "t", "data", "INSERT INTO `t` (`pk`,`c1`) VALUES (2,'two');"},
  3367  				},
  3368  			},
  3369  			// Three dot
  3370  			{
  3371  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('main...branch1', 't');",
  3372  				Expected: []sql.Row{
  3373  					{1, "t", "schema", "ALTER TABLE `t` DROP `c2`;"},
  3374  					{2, "t", "data", "DELETE FROM `t` WHERE `pk`=1;"},
  3375  					{3, "t", "data", "INSERT INTO `t` (`pk`,`c1`) VALUES (2,'two');"},
  3376  				},
  3377  			},
  3378  			{
  3379  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('main...branch1');",
  3380  				Expected: []sql.Row{
  3381  					{1, "t", "schema", "ALTER TABLE `t` DROP `c2`;"},
  3382  					{2, "t", "data", "DELETE FROM `t` WHERE `pk`=1;"},
  3383  					{3, "t", "data", "INSERT INTO `t` (`pk`,`c1`) VALUES (2,'two');"},
  3384  				},
  3385  			},
  3386  			{
  3387  				Query:    "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('branch1...main', 't');",
  3388  				Expected: []sql.Row{{1, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (2,'two','three');"}},
  3389  			},
  3390  			{
  3391  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('branch1...main');",
  3392  				Expected: []sql.Row{
  3393  					{1, "newtable", "schema", "CREATE TABLE `newtable` (\n  `pk` int NOT NULL,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  3394  					{2, "newtable", "data", "INSERT INTO `newtable` (`pk`) VALUES (1);"},
  3395  					{3, "newtable", "data", "INSERT INTO `newtable` (`pk`) VALUES (2);"},
  3396  					{4, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (2,'two','three');"},
  3397  				},
  3398  			},
  3399  			{
  3400  				Query:    "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('branch1...main^');",
  3401  				Expected: []sql.Row{{1, "t", "data", "INSERT INTO `t` (`pk`,`c1`,`c2`) VALUES (2,'two','three');"}},
  3402  			},
  3403  			{
  3404  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('branch1...main', 'newtable');",
  3405  				Expected: []sql.Row{
  3406  					{1, "newtable", "schema", "CREATE TABLE `newtable` (\n  `pk` int NOT NULL,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  3407  					{2, "newtable", "data", "INSERT INTO `newtable` (`pk`) VALUES (1);"},
  3408  					{3, "newtable", "data", "INSERT INTO `newtable` (`pk`) VALUES (2);"},
  3409  				},
  3410  			},
  3411  			{
  3412  				Query:    "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('main...main', 'newtable');",
  3413  				Expected: []sql.Row{},
  3414  			},
  3415  		},
  3416  	},
  3417  	{
  3418  		Name: "renamed table",
  3419  		SetUpScript: []string{
  3420  			"create table t1 (a int primary key, b int)",
  3421  			"call dolt_add('.')",
  3422  			"insert into t1 values (1,2)",
  3423  			"call dolt_commit('-am', 'new table')",
  3424  			"alter table t1 rename to t2",
  3425  			"call dolt_add('.')",
  3426  			"insert into t2 values (3,4)",
  3427  			"call dolt_commit('-am', 'renamed table')",
  3428  		},
  3429  		Assertions: []queries.ScriptTestAssertion{
  3430  			{
  3431  				Query: "select statement_order, table_name, diff_type, statement FROM dolt_patch('HEAD~', 'HEAD', 't2')",
  3432  				Expected: []sql.Row{
  3433  					{1, "t2", "schema", "RENAME TABLE `t1` TO `t2`;"},
  3434  					{2, "t2", "data", "INSERT INTO `t2` (`a`,`b`) VALUES (3,4);"},
  3435  				},
  3436  			},
  3437  			{
  3438  				Query: "select statement_order, table_name, diff_type, statement FROM dolt_patch('HEAD~..HEAD', 't2')",
  3439  				Expected: []sql.Row{
  3440  					{1, "t2", "schema", "RENAME TABLE `t1` TO `t2`;"},
  3441  					{2, "t2", "data", "INSERT INTO `t2` (`a`,`b`) VALUES (3,4);"},
  3442  				},
  3443  			},
  3444  			{
  3445  				// Old table name can be matched as well
  3446  				Query: "select statement_order, table_name, diff_type, statement FROM dolt_patch('HEAD~', 'HEAD', 't1')",
  3447  				Expected: []sql.Row{
  3448  					{1, "t2", "schema", "RENAME TABLE `t1` TO `t2`;"},
  3449  					{2, "t2", "data", "INSERT INTO `t2` (`a`,`b`) VALUES (3,4);"},
  3450  				},
  3451  			},
  3452  			{
  3453  				// Old table name can be matched as well
  3454  				Query: "select statement_order, table_name, diff_type, statement FROM dolt_patch('HEAD~..HEAD', 't1')",
  3455  				Expected: []sql.Row{
  3456  					{1, "t2", "schema", "RENAME TABLE `t1` TO `t2`;"},
  3457  					{2, "t2", "data", "INSERT INTO `t2` (`a`,`b`) VALUES (3,4);"},
  3458  				},
  3459  			},
  3460  		},
  3461  	},
  3462  	{
  3463  		Name: "multi PRIMARY KEY and FOREIGN KEY",
  3464  		SetUpScript: []string{
  3465  			"CREATE TABLE parent (id int PRIMARY KEY, id_ext int, v1 int, v2 text COMMENT 'tag:1', INDEX v1 (v1));",
  3466  			"CREATE TABLE child (id int primary key, v1 int);",
  3467  			"call dolt_commit('-Am', 'new tables')",
  3468  			"ALTER TABLE child ADD CONSTRAINT fk_named FOREIGN KEY (v1) REFERENCES parent(v1);",
  3469  			"insert into parent values (0, 1, 2, NULL);",
  3470  			"ALTER TABLE parent DROP PRIMARY KEY;",
  3471  			"ALTER TABLE parent ADD PRIMARY KEY(id, id_ext);",
  3472  			"call dolt_add('.')",
  3473  		},
  3474  		Assertions: []queries.ScriptTestAssertion{
  3475  			{
  3476  				Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('HEAD~', 'WORKING')",
  3477  				Expected: []sql.Row{
  3478  					{1, "child", "schema", "CREATE TABLE `child` (\n  `id` int NOT NULL,\n  `v1` int,\n  PRIMARY KEY (`id`),\n  KEY `v1` (`v1`),\n  CONSTRAINT `fk_named` FOREIGN KEY (`v1`) REFERENCES `parent` (`v1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  3479  					{2, "parent", "schema", "CREATE TABLE `parent` (\n  `id` int NOT NULL,\n  `id_ext` int NOT NULL,\n  `v1` int,\n  `v2` text COMMENT 'tag:1',\n  PRIMARY KEY (`id`,`id_ext`),\n  KEY `v1` (`v1`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  3480  					{3, "parent", "data", "INSERT INTO `parent` (`id`,`id_ext`,`v1`,`v2`) VALUES (0,1,2,NULL);"},
  3481  				},
  3482  			},
  3483  			{
  3484  				Query: "SELECT statement_order, to_commit_hash, table_name, diff_type, statement FROM dolt_patch('HEAD', 'STAGED')",
  3485  				Expected: []sql.Row{
  3486  					{1, "STAGED", "child", "schema", "ALTER TABLE `child` ADD INDEX `v1`(`v1`);"},
  3487  					{2, "STAGED", "child", "schema", "ALTER TABLE `child` ADD CONSTRAINT `fk_named` FOREIGN KEY (`v1`) REFERENCES `parent` (`v1`);"},
  3488  					{3, "STAGED", "parent", "schema", "ALTER TABLE `parent` DROP PRIMARY KEY;"},
  3489  					{4, "STAGED", "parent", "schema", "ALTER TABLE `parent` ADD PRIMARY KEY (id,id_ext);"},
  3490  				},
  3491  				ExpectedWarningsCount: 1,
  3492  			},
  3493  			{
  3494  				Query: "SHOW WARNINGS;",
  3495  				Expected: []sql.Row{
  3496  					{"Warning", 1235, "Primary key sets differ between revisions for table 'parent', skipping data diff"},
  3497  				},
  3498  			},
  3499  		},
  3500  	},
  3501  	{
  3502  		Name: "CHECK CONSTRAINTS",
  3503  		SetUpScript: []string{
  3504  			"create table foo (pk int, c1 int, CHECK (c1 > 3), PRIMARY KEY (pk));",
  3505  		},
  3506  		Assertions: []queries.ScriptTestAssertion{
  3507  			{
  3508  				Query:    "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('HEAD', 'WORKING')",
  3509  				Expected: []sql.Row{{1, "foo", "schema", "CREATE TABLE `foo` (\n  `pk` int NOT NULL,\n  `c1` int,\n  PRIMARY KEY (`pk`),\n  CONSTRAINT `foo_chk_eq3jn5ra` CHECK ((c1 > 3))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"}},
  3510  			},
  3511  		},
  3512  	},
  3513  	{
  3514  		Name: "charset and collation changes",
  3515  		SetUpScript: []string{
  3516  			"create table t (pk int primary key) collate='utf8mb4_0900_bin';",
  3517  			"call dolt_commit('-Am', 'empty table')",
  3518  			"set @commit0=hashof('HEAD');",
  3519  			"insert into t values (1)",
  3520  			"alter table t collate='utf8mb4_0900_ai_ci';",
  3521  			"call dolt_commit('-am', 'inserting a row and altering the collation')",
  3522  			"set @commit1=hashof('HEAD');",
  3523  			"alter table t CHARACTER SET='utf8mb3';",
  3524  			"insert into t values (2)",
  3525  			"call dolt_commit('-am', 'inserting a row and altering the collation')",
  3526  			"set @commit2=hashof('HEAD');",
  3527  		},
  3528  		Assertions: []queries.ScriptTestAssertion{
  3529  			{
  3530  				Query: "select * from dolt_patch(@commit1, @commit0);",
  3531  				Expected: []sql.Row{
  3532  					{1, doltCommit, doltCommit, "t", "schema", "ALTER TABLE `t` COLLATE='utf8mb4_0900_bin';"},
  3533  					{2, doltCommit, doltCommit, "t", "data", "DELETE FROM `t` WHERE `pk`=1;"},
  3534  				},
  3535  			},
  3536  			{
  3537  				Query: "select * from dolt_patch(@commit1, @commit2);",
  3538  				Expected: []sql.Row{
  3539  					{1, doltCommit, doltCommit, "t", "schema", "ALTER TABLE `t` COLLATE='utf8mb3_general_ci';"},
  3540  					{2, doltCommit, doltCommit, "t", "data", "INSERT INTO `t` (`pk`) VALUES (2);"},
  3541  				},
  3542  			},
  3543  		},
  3544  	},
  3545  	{
  3546  		Name: "patch DDL changes",
  3547  		SetUpScript: []string{
  3548  			"create table t (pk int primary key, a int, b int, c int)",
  3549  			"insert into t values (1, null, 1, 1), (2, 2, null, 2), (3, 3, 3, 3)",
  3550  			"CALL dolt_commit('-Am', 'new table t')",
  3551  			"CALL dolt_checkout('-b', 'other')",
  3552  			"alter table t modify column a varchar(100) comment 'foo';",
  3553  			"alter table t rename column c to z;",
  3554  			"alter table t drop column b",
  3555  			"alter table t add column d int",
  3556  			"delete from t where pk = 3",
  3557  			"update t set a = 9 where a is NULL",
  3558  			"insert into t values (7,7,7,7)",
  3559  			"CALL dolt_commit('-am', 'modified table t')",
  3560  		},
  3561  		Assertions: []queries.ScriptTestAssertion{
  3562  			{
  3563  				Query: "SELECT statement FROM dolt_patch('main', 'other', 't') ORDER BY statement_order",
  3564  				Expected: []sql.Row{
  3565  					{"ALTER TABLE `t` MODIFY COLUMN `a` varchar(100) COMMENT 'foo';"},
  3566  					{"ALTER TABLE `t` DROP `b`;"},
  3567  					{"ALTER TABLE `t` RENAME COLUMN `c` TO `z`;"},
  3568  					{"ALTER TABLE `t` ADD `d` int;"},
  3569  					// TODO: The two updates to z below aren't necessary, since the column
  3570  					//       was renamed and those are the old values, but it shows as a diff
  3571  					//       because of the column name change, so we output UPDATE statements
  3572  					//       for them. This isn't a correctness issue, but it is inefficient.
  3573  					{"UPDATE `t` SET `a`='9',`z`=1 WHERE `pk`=1;"},
  3574  					{"UPDATE `t` SET `z`=2 WHERE `pk`=2;"},
  3575  					{"DELETE FROM `t` WHERE `pk`=3;"},
  3576  					{"INSERT INTO `t` (`pk`,`a`,`z`,`d`) VALUES (7,'7',7,7);"},
  3577  				},
  3578  			},
  3579  		},
  3580  	},
  3581  }
  3582  
  3583  var UnscopedDiffSystemTableScriptTests = []queries.ScriptTest{
  3584  	{
  3585  		Name: "working set changes",
  3586  		SetUpScript: []string{
  3587  			"create table regularTable (a int primary key, b int, c int);",
  3588  			"create table droppedTable (a int primary key, b int, c int);",
  3589  			"create table renamedEmptyTable (a int primary key, b int, c int);",
  3590  			"call dolt_add('.')",
  3591  			"insert into regularTable values (1, 2, 3), (2, 3, 4);",
  3592  			"insert into droppedTable values (1, 2, 3), (2, 3, 4);",
  3593  			"set @Commit1 = '';",
  3594  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating tables x and y');",
  3595  
  3596  			// changeSet: STAGED; data change: false; schema change: true
  3597  			"create table addedTable (a int primary key, b int, c int);",
  3598  			"call DOLT_ADD('addedTable');",
  3599  			// changeSet: STAGED; data change: true; schema change: true
  3600  			"drop table droppedTable;",
  3601  			"call DOLT_ADD('droppedTable');",
  3602  			// changeSet: WORKING; data change: false; schema change: true
  3603  			"rename table renamedEmptyTable to newRenamedEmptyTable",
  3604  			// changeSet: WORKING; data change: true; schema change: false
  3605  			"insert into regularTable values (3, 4, 5);",
  3606  		},
  3607  		Assertions: []queries.ScriptTestAssertion{
  3608  			{
  3609  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF;",
  3610  				Expected: []sql.Row{{7}},
  3611  			},
  3612  			{
  3613  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF WHERE commit_hash = @Commit1;",
  3614  				Expected: []sql.Row{{3}},
  3615  			},
  3616  			{
  3617  				Query:    "SELECT * FROM DOLT_DIFF WHERE commit_hash = @Commit1 AND committer <> 'root';",
  3618  				Expected: []sql.Row{},
  3619  			},
  3620  			{
  3621  				Query:    "SELECT commit_hash, committer FROM DOLT_DIFF WHERE commit_hash <> @Commit1 AND committer = 'root' AND commit_hash NOT IN ('WORKING','STAGED');",
  3622  				Expected: []sql.Row{},
  3623  			},
  3624  			{
  3625  				Query: "SELECT commit_hash, table_name FROM DOLT_DIFF WHERE commit_hash <> @Commit1 AND commit_hash NOT IN ('STAGED') ORDER BY table_name;",
  3626  				Expected: []sql.Row{
  3627  					{"WORKING", "newRenamedEmptyTable"},
  3628  					{"WORKING", "regularTable"},
  3629  				},
  3630  			},
  3631  			{
  3632  				Query: "SELECT commit_hash, table_name FROM DOLT_DIFF WHERE commit_hash <> @Commit1 OR committer <> 'root' ORDER BY table_name;",
  3633  				Expected: []sql.Row{
  3634  					{"STAGED", "addedTable"},
  3635  					{"STAGED", "droppedTable"},
  3636  					{"WORKING", "newRenamedEmptyTable"},
  3637  					{"WORKING", "regularTable"},
  3638  				},
  3639  			},
  3640  			{
  3641  				Query: "SELECT * FROM DOLT_DIFF WHERE COMMIT_HASH in ('WORKING', 'STAGED') ORDER BY table_name;",
  3642  				Expected: []sql.Row{
  3643  					{"STAGED", "addedTable", nil, nil, nil, nil, false, true},
  3644  					{"STAGED", "droppedTable", nil, nil, nil, nil, true, true},
  3645  					{"WORKING", "newRenamedEmptyTable", nil, nil, nil, nil, false, true},
  3646  					{"WORKING", "regularTable", nil, nil, nil, nil, true, false},
  3647  				},
  3648  			},
  3649  		},
  3650  	},
  3651  	{
  3652  		Name: "basic case with three tables",
  3653  		SetUpScript: []string{
  3654  			"create table x (a int primary key, b int, c int);",
  3655  			"create table y (a int primary key, b int, c int);",
  3656  			"call dolt_add('.')",
  3657  			"insert into x values (1, 2, 3), (2, 3, 4);",
  3658  			"set @Commit1 = '';",
  3659  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating tables x and y');",
  3660  
  3661  			"create table z (a int primary key, b int, c int);",
  3662  			"call dolt_add('.')",
  3663  			"insert into z values (100, 101, 102);",
  3664  			"set @Commit2 = '';",
  3665  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'Creating tables z');",
  3666  
  3667  			"insert into y values (-1, -2, -3), (-2, -3, -4);",
  3668  			"insert into z values (101, 102, 103);",
  3669  			"set @Commit3 = '';",
  3670  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'Inserting into tables y and z');",
  3671  
  3672  			"alter table y add column d int;",
  3673  			"set @Commit4 = '';",
  3674  			"CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'Modify schema of table y');",
  3675  		},
  3676  		Assertions: []queries.ScriptTestAssertion{
  3677  			{
  3678  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF",
  3679  				Expected: []sql.Row{{6}},
  3680  			},
  3681  			{
  3682  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash = @Commit1",
  3683  				Expected: []sql.Row{{"x", true, true}, {"y", true, false}},
  3684  			},
  3685  			{
  3686  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit2)",
  3687  				Expected: []sql.Row{{"z", true, true}},
  3688  			},
  3689  			{
  3690  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit3)",
  3691  				Expected: []sql.Row{{"y", false, true}, {"z", false, true}},
  3692  			},
  3693  		},
  3694  	},
  3695  	{
  3696  		Name: "renamed table",
  3697  		SetUpScript: []string{
  3698  			"create table x (a int primary key, b int, c int)",
  3699  			"create table y (a int primary key, b int, c int)",
  3700  			"call dolt_add('.')",
  3701  			"insert into x values (1, 2, 3), (2, 3, 4)",
  3702  			"set @Commit1 = '';",
  3703  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating tables x and y')",
  3704  
  3705  			"create table z (a int primary key, b int, c int)",
  3706  			"call dolt_add('.')",
  3707  			"insert into z values (100, 101, 102)",
  3708  			"set @Commit2 = '';",
  3709  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'Creating tables z')",
  3710  
  3711  			"rename table x to x1",
  3712  			"call dolt_add('.')",
  3713  			"insert into x1 values (1000, 1001, 1002);",
  3714  			"set @Commit3 = '';",
  3715  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'Renaming table x to x1 and inserting data')",
  3716  
  3717  			"rename table x1 to x2",
  3718  			"call dolt_add('.')",
  3719  			"set @Commit4 = '';",
  3720  			"CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'Renaming table x1 to x2')",
  3721  		},
  3722  		Assertions: []queries.ScriptTestAssertion{
  3723  			{
  3724  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF",
  3725  				Expected: []sql.Row{{5}},
  3726  			},
  3727  			{
  3728  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit1)",
  3729  				Expected: []sql.Row{{"x", true, true}, {"y", true, false}},
  3730  			},
  3731  			{
  3732  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit2)",
  3733  				Expected: []sql.Row{{"z", true, true}},
  3734  			},
  3735  			{
  3736  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit3)",
  3737  				Expected: []sql.Row{{"x1", true, true}},
  3738  			},
  3739  			{
  3740  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit4)",
  3741  				Expected: []sql.Row{{"x2", true, false}},
  3742  			},
  3743  		},
  3744  	},
  3745  	{
  3746  		Name: "dropped table",
  3747  		SetUpScript: []string{
  3748  			"create table x (a int primary key, b int, c int)",
  3749  			"create table y (a int primary key, b int, c int)",
  3750  			"call dolt_add('.')",
  3751  			"insert into x values (1, 2, 3), (2, 3, 4)",
  3752  			"set @Commit1 = '';",
  3753  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating tables x and y')",
  3754  
  3755  			"drop table x",
  3756  			"set @Commit2 = '';",
  3757  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'Dropping non-empty table x')",
  3758  
  3759  			"drop table y",
  3760  			"set @Commit3 = '';",
  3761  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'Dropping empty table y')",
  3762  		},
  3763  		Assertions: []queries.ScriptTestAssertion{
  3764  			{
  3765  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF",
  3766  				Expected: []sql.Row{{4}},
  3767  			},
  3768  			{
  3769  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit1)",
  3770  				Expected: []sql.Row{{"x", true, true}, {"y", true, false}},
  3771  			},
  3772  			{
  3773  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit2)",
  3774  				Expected: []sql.Row{{"x", true, true}},
  3775  			},
  3776  			{
  3777  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit3)",
  3778  				Expected: []sql.Row{{"y", true, false}},
  3779  			},
  3780  		},
  3781  	},
  3782  	{
  3783  		Name: "empty commit handling",
  3784  		SetUpScript: []string{
  3785  			"create table x (a int primary key, b int, c int)",
  3786  			"create table y (a int primary key, b int, c int)",
  3787  			"call dolt_add('.')",
  3788  			"insert into x values (1, 2, 3), (2, 3, 4)",
  3789  			"set @Commit1 = '';",
  3790  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating tables x and y')",
  3791  			"set @Commit2 = '';",
  3792  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '--allow-empty', '-m', 'Empty!')",
  3793  			"insert into y values (-1, -2, -3), (-2, -3, -4)",
  3794  			"set @Commit3 = '';",
  3795  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'Inserting into table y')",
  3796  		},
  3797  		Assertions: []queries.ScriptTestAssertion{
  3798  			{
  3799  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF",
  3800  				Expected: []sql.Row{{3}},
  3801  			},
  3802  			{
  3803  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit1)",
  3804  				Expected: []sql.Row{{"x", true, true}, {"y", true, false}},
  3805  			},
  3806  			{
  3807  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit2)",
  3808  				Expected: []sql.Row{},
  3809  			},
  3810  			{
  3811  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit3)",
  3812  				Expected: []sql.Row{{"y", false, true}},
  3813  			},
  3814  		},
  3815  	},
  3816  	{
  3817  		Name: "includes commits from all branches",
  3818  		SetUpScript: []string{
  3819  			"CALL DOLT_checkout('-b', 'branch1')",
  3820  			"create table x (a int primary key, b int, c int)",
  3821  			"create table y (a int primary key, b int, c int)",
  3822  			"call dolt_add('.')",
  3823  			"insert into x values (1, 2, 3), (2, 3, 4)",
  3824  			"set @Commit1 = '';",
  3825  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating tables x and y')",
  3826  
  3827  			"CALL DOLT_checkout('-b', 'branch2')",
  3828  			"create table z (a int primary key, b int, c int)",
  3829  			"call dolt_add('.')",
  3830  			"insert into z values (100, 101, 102)",
  3831  			"set @Commit2 = '';",
  3832  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'Creating tables z')",
  3833  
  3834  			"insert into y values (-1, -2, -3), (-2, -3, -4)",
  3835  			"insert into z values (101, 102, 103)",
  3836  			"set @Commit3 = '';",
  3837  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'Inserting into tables y and z')",
  3838  		},
  3839  		Assertions: []queries.ScriptTestAssertion{
  3840  			{
  3841  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF",
  3842  				Expected: []sql.Row{{5}},
  3843  			},
  3844  			{
  3845  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit1)",
  3846  				Expected: []sql.Row{{"x", true, true}, {"y", true, false}},
  3847  			},
  3848  			{
  3849  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit2)",
  3850  				Expected: []sql.Row{{"z", true, true}},
  3851  			},
  3852  			{
  3853  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit3)",
  3854  				Expected: []sql.Row{{"y", false, true}, {"z", false, true}},
  3855  			},
  3856  		},
  3857  	},
  3858  	// The DOLT_DIFF system table doesn't currently show any diff data for a merge commit.
  3859  	// When processing a merge commit, diff.GetTableDeltas isn't aware of branch context, so it
  3860  	// doesn't detect that any tables have changed.
  3861  	{
  3862  		Name: "merge history handling",
  3863  		SetUpScript: []string{
  3864  			"CALL DOLT_checkout('-b', 'branch1')",
  3865  			"create table x (a int primary key, b int, c int)",
  3866  			"create table y (a int primary key, b int, c int)",
  3867  			"insert into x values (1, 2, 3), (2, 3, 4)",
  3868  			"set @Commit1 = ''",
  3869  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-Am', 'Creating tables x and y')",
  3870  
  3871  			"CALL DOLT_checkout('-b', 'branch2', 'HEAD~1')",
  3872  			"create table z (a int primary key, b int, c int)",
  3873  			"insert into z values (100, 101, 102)",
  3874  			"set @Commit2 = ''",
  3875  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-Am', 'Creating tables z')",
  3876  
  3877  			"CALL DOLT_MERGE('--no-commit', 'branch1')",
  3878  			"set @Commit3 = ''",
  3879  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'Merging branch1 into branch2')",
  3880  		},
  3881  		Assertions: []queries.ScriptTestAssertion{
  3882  			{
  3883  				Query:    "SELECT COUNT(*) FROM DOLT_DIFF",
  3884  				Expected: []sql.Row{{5}},
  3885  			},
  3886  			{
  3887  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit1)",
  3888  				Expected: []sql.Row{{"x", true, true}, {"y", true, false}},
  3889  			},
  3890  			{
  3891  				Query:    "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit2)",
  3892  				Expected: []sql.Row{{"z", true, true}},
  3893  			},
  3894  			{
  3895  				Query: "select table_name, schema_change, data_change from DOLT_DIFF where commit_hash in (@Commit3) order by table_name",
  3896  				Expected: []sql.Row{
  3897  					{"x", true, true},
  3898  					{"y", true, false},
  3899  				},
  3900  			},
  3901  		},
  3902  	},
  3903  }
  3904  
  3905  var ColumnDiffSystemTableScriptTests = []queries.ScriptTest{
  3906  	{
  3907  		Name: "table changes - commit history",
  3908  		SetUpScript: []string{
  3909  			"create table modifiedTable (a int primary key, b int);",
  3910  			"insert into modifiedTable values (1, 2), (2, 3);",
  3911  			"create table droppedTable (a int primary key, b int);",
  3912  			"insert into droppedTable values (1, 2), (2, 3);",
  3913  			"create table renamedTable (a int primary key, b int);",
  3914  			"call dolt_add('.')",
  3915  			"call dolt_commit('-am', 'creating tables');",
  3916  
  3917  			"update modifiedTable set b = 5 where a = 1;",
  3918  			"drop table droppedTable;",
  3919  			"rename table renamedTable to newRenamedTable;",
  3920  			"create table addedTable (a int primary key, b int);",
  3921  			"call dolt_add('.')",
  3922  			"call dolt_commit('-am', 'make table changes');",
  3923  		},
  3924  		Assertions: []queries.ScriptTestAssertion{
  3925  			{
  3926  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'modifiedTable';",
  3927  				Expected: []sql.Row{
  3928  					{"modifiedTable", "a", "added"},
  3929  					{"modifiedTable", "b", "added"},
  3930  					{"modifiedTable", "b", "modified"},
  3931  				},
  3932  			},
  3933  			{
  3934  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'droppedTable';",
  3935  				Expected: []sql.Row{
  3936  					{"droppedTable", "a", "added"},
  3937  					{"droppedTable", "b", "added"},
  3938  					{"droppedTable", "a", "removed"},
  3939  					{"droppedTable", "b", "removed"},
  3940  				},
  3941  			},
  3942  			{
  3943  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'renamedTable' OR table_name = 'newRenamedTable';",
  3944  				Expected: []sql.Row{
  3945  					{"renamedTable", "a", "added"},
  3946  					{"renamedTable", "b", "added"},
  3947  				},
  3948  			},
  3949  			{
  3950  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'addedTable';",
  3951  				Expected: []sql.Row{
  3952  					{"addedTable", "a", "added"},
  3953  					{"addedTable", "b", "added"},
  3954  				},
  3955  			},
  3956  		},
  3957  	},
  3958  	{
  3959  		Name: "table changes - working set",
  3960  		SetUpScript: []string{
  3961  			"create table modifiedTable (a int primary key, b int);",
  3962  			"insert into modifiedTable values (1, 2), (2, 3);",
  3963  			"create table droppedTable (a int primary key, b int);",
  3964  			"insert into droppedTable values (1, 2), (2, 3);",
  3965  			"create table renamedTable (a int primary key, b int);",
  3966  			"call dolt_add('.')",
  3967  
  3968  			"update modifiedTable set b = 5 where a = 1;",
  3969  			"drop table droppedTable;",
  3970  			"rename table renamedTable to newRenamedTable;",
  3971  			"create table addedTable (a int primary key, b int);",
  3972  		},
  3973  		Assertions: []queries.ScriptTestAssertion{
  3974  			{
  3975  				Query: "SELECT commit_hash, table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'modifiedTable' ORDER BY commit_hash, table_name, column_name;",
  3976  				Expected: []sql.Row{
  3977  					{"STAGED", "modifiedTable", "a", "added"},
  3978  					{"STAGED", "modifiedTable", "b", "added"},
  3979  					{"WORKING", "modifiedTable", "b", "modified"},
  3980  				},
  3981  			},
  3982  			{
  3983  				Query: "SELECT commit_hash, table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'droppedTable' ORDER BY commit_hash, table_name, column_name;",
  3984  				Expected: []sql.Row{
  3985  					{"STAGED", "droppedTable", "a", "added"},
  3986  					{"STAGED", "droppedTable", "b", "added"},
  3987  					{"WORKING", "droppedTable", "a", "removed"},
  3988  					{"WORKING", "droppedTable", "b", "removed"},
  3989  				},
  3990  			},
  3991  			{
  3992  				Query: "SELECT commit_hash, table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'renamedTable' OR table_name = 'newRenamedTable' ORDER BY commit_hash, table_name, column_name;",
  3993  				Expected: []sql.Row{
  3994  					{"STAGED", "renamedTable", "a", "added"},
  3995  					{"STAGED", "renamedTable", "b", "added"},
  3996  				},
  3997  			},
  3998  			{
  3999  				Query: "SELECT commit_hash, table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'addedTable' ORDER BY commit_hash, table_name, column_name;",
  4000  				Expected: []sql.Row{
  4001  					{"WORKING", "addedTable", "a", "added"},
  4002  					{"WORKING", "addedTable", "b", "added"},
  4003  				},
  4004  			},
  4005  		},
  4006  	},
  4007  	{
  4008  		Name: "add column - commit history",
  4009  		SetUpScript: []string{
  4010  			"create table t (pk int primary key, c int);",
  4011  			"call dolt_add('.')",
  4012  			"insert into t values (1, 2), (3, 4);",
  4013  			"set @Commit1 = '';",
  4014  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
  4015  
  4016  			"alter table t add column d int;",
  4017  			"set @Commit2 = '';",
  4018  			"call dolt_add('.')",
  4019  			"call dolt_commit_hash_out(@Commit2, '-m', 'updating d in t');",
  4020  		},
  4021  		Assertions: []queries.ScriptTestAssertion{
  4022  			{
  4023  				Query:    "select count(*) from dolt_column_diff where commit_hash = @Commit1;",
  4024  				Expected: []sql.Row{{2}},
  4025  			},
  4026  			{
  4027  				Query:    "select table_name, column_name, diff_type from dolt_column_diff where commit_hash = @Commit2;",
  4028  				Expected: []sql.Row{{"t", "d", "added"}},
  4029  			},
  4030  		},
  4031  	},
  4032  	{
  4033  		Name: "add column - working set",
  4034  		SetUpScript: []string{
  4035  			"create table t (pk int primary key, c int);",
  4036  			"insert into t values (1, 2), (3, 4);",
  4037  			"call dolt_add('.')",
  4038  
  4039  			"alter table t add column d int;",
  4040  		},
  4041  		Assertions: []queries.ScriptTestAssertion{
  4042  			{
  4043  				Query:    "select count(*) from dolt_column_diff where commit_hash = 'STAGED';",
  4044  				Expected: []sql.Row{{2}},
  4045  			},
  4046  			{
  4047  				Query:    "select table_name, column_name, diff_type from dolt_column_diff where commit_hash = 'WORKING';",
  4048  				Expected: []sql.Row{{"t", "d", "added"}},
  4049  			},
  4050  		},
  4051  	},
  4052  	{
  4053  		Name: "modify column - commit history",
  4054  		SetUpScript: []string{
  4055  			"create table t (pk int primary key, c int);",
  4056  			"call dolt_add('.')",
  4057  			"insert into t values (1, 2), (3, 4);",
  4058  			"set @Commit1 = '';",
  4059  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
  4060  
  4061  			"update t set c = 5 where pk = 3;",
  4062  			"call dolt_add('.')",
  4063  			"set @Commit2 = '';",
  4064  			"call dolt_commit_hash_out(@Commit2, '-am', 'updating value in t');",
  4065  		},
  4066  		Assertions: []queries.ScriptTestAssertion{
  4067  			{
  4068  				Query:    "select count(*) from dolt_column_diff where commit_hash = @Commit1;",
  4069  				Expected: []sql.Row{{2}},
  4070  			},
  4071  			{
  4072  				Query:    "select table_name, column_name, diff_type from dolt_column_diff where commit_hash = @Commit2;",
  4073  				Expected: []sql.Row{{"t", "c", "modified"}},
  4074  			},
  4075  		},
  4076  	},
  4077  	{
  4078  		Name: "modify column - working set",
  4079  		SetUpScript: []string{
  4080  			"create table t (pk int primary key, c int);",
  4081  			"insert into t values (1, 2), (3, 4);",
  4082  			"call dolt_add('.')",
  4083  
  4084  			"update t set c = 5 where pk = 3;",
  4085  		},
  4086  		Assertions: []queries.ScriptTestAssertion{
  4087  			{
  4088  				Query:    "select count(*) from dolt_column_diff where commit_hash = 'STAGED';",
  4089  				Expected: []sql.Row{{2}},
  4090  			},
  4091  			{
  4092  				Query:    "select table_name, column_name, diff_type from dolt_column_diff where commit_hash = 'WORKING';",
  4093  				Expected: []sql.Row{{"t", "c", "modified"}},
  4094  			},
  4095  		},
  4096  	},
  4097  	{
  4098  		Name: "drop column - commit history",
  4099  		SetUpScript: []string{
  4100  			"create table t (pk int primary key, c int);",
  4101  			"call dolt_add('.')",
  4102  			"insert into t values (1, 2), (3, 4);",
  4103  			"set @Commit1 = '';",
  4104  			"call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');",
  4105  
  4106  			"alter table t drop column c;",
  4107  			"call dolt_add('.')",
  4108  			"set @Commit2 = '';",
  4109  			"call dolt_commit_hash_out(@Commit2, '-am', 'dropping column c in t');",
  4110  		},
  4111  		Assertions: []queries.ScriptTestAssertion{
  4112  			{
  4113  				Query:    "select count(*) from dolt_column_diff where commit_hash = @Commit1;",
  4114  				Expected: []sql.Row{{2}},
  4115  			},
  4116  			{
  4117  				Query:    "select table_name, column_name, diff_type from dolt_column_diff where commit_hash = @Commit2;",
  4118  				Expected: []sql.Row{{"t", "c", "removed"}},
  4119  			},
  4120  		},
  4121  	},
  4122  	{
  4123  		Name: "drop column - working set",
  4124  		SetUpScript: []string{
  4125  			"create table t (pk int primary key, c int);",
  4126  			"insert into t values (1, 2), (3, 4);",
  4127  			"call dolt_add('.')",
  4128  
  4129  			"alter table t drop column c;",
  4130  		},
  4131  		Assertions: []queries.ScriptTestAssertion{
  4132  			{
  4133  				Query:    "select count(*) from dolt_column_diff where commit_hash = 'STAGED';",
  4134  				Expected: []sql.Row{{2}},
  4135  			},
  4136  			{
  4137  				Query:    "select table_name, column_name, diff_type from dolt_column_diff where commit_hash = 'WORKING';",
  4138  				Expected: []sql.Row{{"t", "c", "removed"}},
  4139  			},
  4140  		},
  4141  	},
  4142  	{
  4143  		Name: "drop column and recreate with same type - commit history",
  4144  		SetUpScript: []string{
  4145  			"create table t (pk int primary key, c int);",
  4146  			"call dolt_add('.')",
  4147  			"insert into t values (1, 2), (3, 4);",
  4148  			"set @Commit1 = '';",
  4149  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4150  
  4151  			"alter table t drop column c;",
  4152  			"set @Commit2 = '';",
  4153  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');",
  4154  
  4155  			"alter table t add column c int;",
  4156  			"insert into t values (100, 101);",
  4157  			"set @Commit3 = '';",
  4158  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'inserting into t');",
  4159  		},
  4160  		Assertions: []queries.ScriptTestAssertion{
  4161  			{
  4162  				Query:    "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
  4163  				Expected: []sql.Row{{5}},
  4164  			},
  4165  			{
  4166  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit1;",
  4167  				Expected: []sql.Row{
  4168  					{"t", "pk", "added"},
  4169  					{"t", "c", "added"},
  4170  				},
  4171  			},
  4172  			{
  4173  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit2;",
  4174  				Expected: []sql.Row{
  4175  					{"t", "c", "removed"},
  4176  				},
  4177  			},
  4178  			{
  4179  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit3",
  4180  				Expected: []sql.Row{
  4181  					{"t", "pk", "modified"},
  4182  					{"t", "c", "added"},
  4183  				},
  4184  			},
  4185  		},
  4186  	},
  4187  	{
  4188  		Name: "drop column and recreate with same type - working set",
  4189  		SetUpScript: []string{
  4190  			"create table t (pk int primary key, c int);",
  4191  			"insert into t values (1, 2), (3, 4);",
  4192  			"call dolt_add('.')",
  4193  
  4194  			"alter table t drop column c;",
  4195  			"alter table t add column c int;",
  4196  			"insert into t values (100, 101);",
  4197  		},
  4198  		Assertions: []queries.ScriptTestAssertion{
  4199  			{
  4200  				Query:    "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
  4201  				Expected: []sql.Row{{4}},
  4202  			},
  4203  			{
  4204  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='STAGED';",
  4205  				Expected: []sql.Row{
  4206  					{"t", "pk", "added"},
  4207  					{"t", "c", "added"},
  4208  				},
  4209  			},
  4210  			{
  4211  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='WORKING';",
  4212  				Expected: []sql.Row{
  4213  					{"t", "pk", "modified"},
  4214  					{"t", "c", "modified"},
  4215  				},
  4216  			},
  4217  		},
  4218  	},
  4219  	{
  4220  		Name: "drop column, then rename column with same type to same name - commit history",
  4221  		SetUpScript: []string{
  4222  			"create table t (pk int primary key, c1 int, c2 int);",
  4223  			"call dolt_add('.')",
  4224  			"insert into t values (1, 2, 3), (4, 5, 6);",
  4225  			"set @Commit1 = '';",
  4226  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4227  
  4228  			"alter table t drop column c1;",
  4229  			"set @Commit2 = '';",
  4230  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c1');",
  4231  
  4232  			"alter table t rename column c2 to c1;",
  4233  			"insert into t values (100, 101);",
  4234  			"set @Commit3 = '';",
  4235  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'inserting into t');",
  4236  		},
  4237  		Assertions: []queries.ScriptTestAssertion{
  4238  			{
  4239  				Query:    "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
  4240  				Expected: []sql.Row{{6}},
  4241  			},
  4242  			{
  4243  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit1;",
  4244  				Expected: []sql.Row{
  4245  					{"t", "pk", "added"},
  4246  					{"t", "c1", "added"},
  4247  					{"t", "c2", "added"},
  4248  				},
  4249  			},
  4250  			{
  4251  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit2;",
  4252  				Expected: []sql.Row{
  4253  					{"t", "c1", "removed"},
  4254  				},
  4255  			},
  4256  			{
  4257  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit3;",
  4258  				Expected: []sql.Row{
  4259  					{"t", "pk", "modified"},
  4260  					{"t", "c1", "modified"},
  4261  				},
  4262  			},
  4263  		},
  4264  	},
  4265  	{
  4266  		Name: "drop column, then rename column with same type to same name - working set",
  4267  		SetUpScript: []string{
  4268  			"create table t (pk int primary key, c1 int, c2 int);",
  4269  			"insert into t values (1, 2, 3), (4, 5, 6);",
  4270  			"call dolt_add('.')",
  4271  
  4272  			"alter table t drop column c1;",
  4273  			"alter table t rename column c2 to c1;",
  4274  			"insert into t values (100, 101);",
  4275  		},
  4276  		Assertions: []queries.ScriptTestAssertion{
  4277  			{
  4278  				Query:    "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
  4279  				Expected: []sql.Row{{6}},
  4280  			},
  4281  			{
  4282  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='STAGED';",
  4283  				Expected: []sql.Row{
  4284  					{"t", "pk", "added"},
  4285  					{"t", "c1", "added"},
  4286  					{"t", "c2", "added"},
  4287  				},
  4288  			},
  4289  			{
  4290  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='WORKING';",
  4291  				Expected: []sql.Row{
  4292  					{"t", "pk", "modified"},
  4293  					{"t", "c1", "removed"},
  4294  					{"t", "c1", "modified"},
  4295  				},
  4296  			},
  4297  		},
  4298  	},
  4299  	{
  4300  		Name: "column drop and recreate with different type that can be coerced (int -> string) - commit history",
  4301  		SetUpScript: []string{
  4302  			"create table t (pk int primary key, c int);",
  4303  			"call dolt_add('.')",
  4304  			"insert into t values (1, 2), (3, 4);",
  4305  			"set @Commit1 = '';",
  4306  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4307  
  4308  			"alter table t drop column c;",
  4309  			"set @Commit2 = '';",
  4310  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');",
  4311  
  4312  			"alter table t add column c varchar(20);",
  4313  			"insert into t values (100, '101');",
  4314  			"set @Commit3 = '';",
  4315  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 're-adding column c');",
  4316  		},
  4317  		Assertions: []queries.ScriptTestAssertion{
  4318  			{
  4319  				Query:    "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
  4320  				Expected: []sql.Row{{5}},
  4321  			},
  4322  			{
  4323  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit1;",
  4324  				Expected: []sql.Row{
  4325  					{"t", "pk", "added"},
  4326  					{"t", "c", "added"},
  4327  				},
  4328  			},
  4329  			{
  4330  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit2;",
  4331  				Expected: []sql.Row{
  4332  					{"t", "c", "removed"},
  4333  				},
  4334  			},
  4335  			{
  4336  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit3;",
  4337  				Expected: []sql.Row{
  4338  					{"t", "pk", "modified"},
  4339  					{"t", "c", "added"},
  4340  				},
  4341  			},
  4342  		},
  4343  	},
  4344  	{
  4345  		Name: "column drop and recreate with different type that can be coerced (int -> string) - working set",
  4346  		SetUpScript: []string{
  4347  			"create table t (pk int primary key, c int);",
  4348  			"insert into t values (1, 2), (3, 4);",
  4349  			"call dolt_add('.')",
  4350  
  4351  			"alter table t drop column c;",
  4352  			"alter table t add column c varchar(20);",
  4353  			"insert into t values (100, '101');",
  4354  		},
  4355  		Assertions: []queries.ScriptTestAssertion{
  4356  			{
  4357  				Query:    "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
  4358  				Expected: []sql.Row{{5}},
  4359  			},
  4360  			{
  4361  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='STAGED';",
  4362  				Expected: []sql.Row{
  4363  					{"t", "pk", "added"},
  4364  					{"t", "c", "added"},
  4365  				},
  4366  			},
  4367  			{
  4368  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='WORKING';",
  4369  				Expected: []sql.Row{
  4370  					{"t", "pk", "modified"},
  4371  					{"t", "c", "removed"},
  4372  					{"t", "c", "added"},
  4373  				},
  4374  			},
  4375  		},
  4376  	},
  4377  	{
  4378  		Name: "column drop and recreate with different type that can NOT be coerced (string -> int) - commit history",
  4379  		SetUpScript: []string{
  4380  			"create table t (pk int primary key, c varchar(20));",
  4381  			"call dolt_add('.')",
  4382  			"insert into t values (1, 'two'), (3, 'four');",
  4383  			"set @Commit1 = '';",
  4384  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4385  
  4386  			"alter table t drop column c;",
  4387  			"set @Commit2 = '';",
  4388  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');",
  4389  
  4390  			"alter table t add column c int;",
  4391  			"insert into t values (100, 101);",
  4392  			"set @Commit3 = '';",
  4393  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 're-adding column c');",
  4394  		},
  4395  		Assertions: []queries.ScriptTestAssertion{
  4396  			{
  4397  				Query:    "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
  4398  				Expected: []sql.Row{{5}},
  4399  			},
  4400  			{
  4401  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit1;",
  4402  				Expected: []sql.Row{
  4403  					{"t", "pk", "added"},
  4404  					{"t", "c", "added"},
  4405  				},
  4406  			},
  4407  			{
  4408  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit2;",
  4409  				Expected: []sql.Row{
  4410  					{"t", "c", "removed"},
  4411  				},
  4412  			},
  4413  			{
  4414  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit3;",
  4415  				Expected: []sql.Row{
  4416  					{"t", "pk", "modified"},
  4417  					{"t", "c", "added"},
  4418  				},
  4419  			},
  4420  		},
  4421  	},
  4422  	{
  4423  		Name: "column drop and recreate with different type that can NOT be coerced (string -> int) - working set",
  4424  		SetUpScript: []string{
  4425  			"create table t (pk int primary key, c varchar(20));",
  4426  			"insert into t values (1, 'two'), (3, 'four');",
  4427  			"call dolt_add('.')",
  4428  
  4429  			"alter table t drop column c;",
  4430  			"alter table t add column c int;",
  4431  			"insert into t values (100, 101);",
  4432  		},
  4433  		Assertions: []queries.ScriptTestAssertion{
  4434  			{
  4435  				Query:    "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
  4436  				Expected: []sql.Row{{5}},
  4437  			},
  4438  			{
  4439  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='STAGED';",
  4440  				Expected: []sql.Row{
  4441  					{"t", "pk", "added"},
  4442  					{"t", "c", "added"},
  4443  				},
  4444  			},
  4445  			{
  4446  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='WORKING';",
  4447  				Expected: []sql.Row{
  4448  					{"t", "pk", "modified"},
  4449  					{"t", "c", "removed"},
  4450  					{"t", "c", "added"},
  4451  				},
  4452  			},
  4453  		},
  4454  	},
  4455  	{
  4456  		Name: "multiple column renames - commit history",
  4457  		SetUpScript: []string{
  4458  			"create table t (pk int primary key, c1 int);",
  4459  			"call dolt_add('.')",
  4460  			"insert into t values (1, 2);",
  4461  			"set @Commit1 = '';",
  4462  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4463  
  4464  			"alter table t rename column c1 to c2;",
  4465  			"insert into t values (3, 4);",
  4466  			"set @Commit2 = '';",
  4467  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'renaming c1 to c2');",
  4468  
  4469  			"alter table t drop column c2;",
  4470  			"set @Commit3 = '';",
  4471  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'dropping column c2');",
  4472  
  4473  			"alter table t add column c2 int;",
  4474  			"insert into t values (100, '101');",
  4475  			"set @Commit4 = '';",
  4476  			"CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'recreating column c2');",
  4477  		},
  4478  		Assertions: []queries.ScriptTestAssertion{
  4479  			{
  4480  				Query:    "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
  4481  				Expected: []sql.Row{{7}},
  4482  			},
  4483  			{
  4484  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit1;",
  4485  				Expected: []sql.Row{
  4486  					{"t", "pk", "added"},
  4487  					{"t", "c1", "added"},
  4488  				},
  4489  			},
  4490  			{
  4491  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit2;",
  4492  				Expected: []sql.Row{
  4493  					{"t", "pk", "modified"},
  4494  					{"t", "c2", "modified"},
  4495  				},
  4496  			},
  4497  			{
  4498  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit3;",
  4499  				Expected: []sql.Row{
  4500  					{"t", "c2", "removed"},
  4501  				},
  4502  			},
  4503  			{
  4504  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit4;",
  4505  				Expected: []sql.Row{
  4506  					{"t", "pk", "modified"},
  4507  					{"t", "c2", "added"},
  4508  				},
  4509  			},
  4510  		},
  4511  	},
  4512  	{
  4513  		Name: "multiple column renames - working set",
  4514  		SetUpScript: []string{
  4515  			"create table t (pk int primary key, c1 int);",
  4516  			"insert into t values (1, 2);",
  4517  			"call dolt_add('.')",
  4518  
  4519  			"alter table t rename column c1 to c2;",
  4520  			"insert into t values (3, 4);",
  4521  
  4522  			"alter table t drop column c2;",
  4523  			"alter table t add column c2 int;",
  4524  			"insert into t values (100, '101');",
  4525  		},
  4526  		Assertions: []queries.ScriptTestAssertion{
  4527  			{
  4528  				Query:    "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
  4529  				Expected: []sql.Row{{5}},
  4530  			},
  4531  			{
  4532  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='STAGED';",
  4533  				Expected: []sql.Row{
  4534  					{"t", "pk", "added"},
  4535  					{"t", "c1", "added"},
  4536  				},
  4537  			},
  4538  			{
  4539  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='WORKING';",
  4540  				Expected: []sql.Row{
  4541  					{"t", "pk", "modified"},
  4542  					{"t", "c1", "removed"},
  4543  					{"t", "c2", "added"},
  4544  				},
  4545  			},
  4546  		},
  4547  	},
  4548  	{
  4549  		Name: "primary key change - commit history",
  4550  		SetUpScript: []string{
  4551  			"create table t (pk int primary key, c1 int);",
  4552  			"call dolt_add('.')",
  4553  			"insert into t values (1, 2), (3, 4);",
  4554  			"set @Commit1 = '';",
  4555  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4556  
  4557  			"alter table t drop primary key;",
  4558  			"insert into t values (5, 6);",
  4559  			"set @Commit2 = '';",
  4560  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping primary key');",
  4561  
  4562  			"alter table t add primary key (c1);",
  4563  			"set @Commit3 = '';",
  4564  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'adding primary key');",
  4565  
  4566  			"insert into t values (7, 8);",
  4567  			"set @Commit4 = '';",
  4568  			"CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'adding more data');",
  4569  		},
  4570  		Assertions: []queries.ScriptTestAssertion{
  4571  			{
  4572  				Query:    "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
  4573  				Expected: []sql.Row{{8}},
  4574  			},
  4575  			{
  4576  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit1;",
  4577  				Expected: []sql.Row{
  4578  					{"t", "pk", "added"},
  4579  					{"t", "c1", "added"},
  4580  				},
  4581  			},
  4582  			{
  4583  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit2;",
  4584  				Expected: []sql.Row{
  4585  					{"t", "pk", "modified"},
  4586  					{"t", "c1", "modified"},
  4587  				},
  4588  			},
  4589  			{
  4590  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit3;",
  4591  				Expected: []sql.Row{
  4592  					{"t", "pk", "modified"},
  4593  					{"t", "c1", "modified"},
  4594  				},
  4595  			},
  4596  			{
  4597  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash=@Commit4;",
  4598  				Expected: []sql.Row{
  4599  					{"t", "pk", "modified"},
  4600  					{"t", "c1", "modified"},
  4601  				},
  4602  			},
  4603  		},
  4604  	},
  4605  	{
  4606  		Name: "primary key change - working set",
  4607  		SetUpScript: []string{
  4608  			"create table t (pk int primary key, c1 int);",
  4609  			"insert into t values (1, 2), (3, 4);",
  4610  			"call dolt_add('.')",
  4611  
  4612  			"alter table t drop primary key;",
  4613  			"alter table t add primary key (c1);",
  4614  			"insert into t values (7, 8);",
  4615  		},
  4616  		Assertions: []queries.ScriptTestAssertion{
  4617  			{
  4618  				Query:    "SELECT COUNT(*) FROM DOLT_COLUMN_DIFF;",
  4619  				Expected: []sql.Row{{4}},
  4620  			},
  4621  			{
  4622  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='STAGED';",
  4623  				Expected: []sql.Row{
  4624  					{"t", "pk", "added"},
  4625  					{"t", "c1", "added"},
  4626  				},
  4627  			},
  4628  			{
  4629  				Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE commit_hash='WORKING';",
  4630  				Expected: []sql.Row{
  4631  					{"t", "pk", "modified"},
  4632  					{"t", "c1", "modified"},
  4633  				},
  4634  			},
  4635  		},
  4636  	},
  4637  	{
  4638  		Name: "json column change",
  4639  		SetUpScript: []string{
  4640  			"create table t (pk int primary key, j json);",
  4641  			`insert into t values (1, '{"test": 123}');`,
  4642  			"call dolt_add('.')",
  4643  			"call dolt_commit('-m', 'commit1');",
  4644  
  4645  			`update t set j = '{"nottest": 321}'`,
  4646  			"call dolt_add('.')",
  4647  			"call dolt_commit('-m', 'commit2');",
  4648  		},
  4649  		Assertions: []queries.ScriptTestAssertion{
  4650  			{
  4651  				Query: "select column_name, diff_type from dolt_column_diff;",
  4652  				Expected: []sql.Row{
  4653  					{"j", "modified"},
  4654  					{"pk", "added"},
  4655  					{"j", "added"},
  4656  				},
  4657  			},
  4658  		},
  4659  	},
  4660  }
  4661  
  4662  var CommitDiffSystemTableScriptTests = []queries.ScriptTest{
  4663  	{
  4664  		Name: "error handling",
  4665  		SetUpScript: []string{
  4666  			"create table t (pk int primary key, c1 int, c2 int);",
  4667  			"call dolt_add('.')",
  4668  			"insert into t values (1, 2, 3), (4, 5, 6);",
  4669  			"set @Commit1 = '';",
  4670  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4671  		},
  4672  		Assertions: []queries.ScriptTestAssertion{
  4673  			{
  4674  				Query:          "SELECT * FROM DOLT_COMMIT_DIFF_t;",
  4675  				ExpectedErrStr: "error querying table dolt_commit_diff_t: dolt_commit_diff_* tables must be filtered to a single 'to_commit'",
  4676  			},
  4677  			{
  4678  				Query:          "SELECT * FROM DOLT_COMMIT_DIFF_t where to_commit=@Commit1;",
  4679  				ExpectedErrStr: dtables.ErrInvalidCommitDiffTableArgs.Error(),
  4680  			},
  4681  			{
  4682  				Query:          "SELECT * FROM DOLT_COMMIT_DIFF_t where from_commit=@Commit1;",
  4683  				ExpectedErrStr: "error querying table dolt_commit_diff_t: dolt_commit_diff_* tables must be filtered to a single 'to_commit'",
  4684  			},
  4685  		},
  4686  	},
  4687  	{
  4688  		Name: "base case: insert, update, delete",
  4689  		SetUpScript: []string{
  4690  			"set @Commit0 = HASHOF('HEAD');",
  4691  			"create table t (pk int primary key, c1 int, c2 int);",
  4692  			"call dolt_add('.')",
  4693  			"insert into t values (1, 2, 3), (4, 5, 6);",
  4694  			"set @Commit1 = '';",
  4695  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4696  
  4697  			"update t set c2=0 where pk=1",
  4698  			"set @Commit2 = '';",
  4699  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'modifying row');",
  4700  
  4701  			"update t set c2=-1 where pk=1",
  4702  			"set @Commit3 = '';",
  4703  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'modifying row');",
  4704  
  4705  			"update t set c2=-2 where pk=1",
  4706  			"set @Commit4 = '';",
  4707  			"CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'modifying row');",
  4708  
  4709  			"delete from t where pk=1",
  4710  			"set @Commit5 = '';",
  4711  			"CALL DOLT_COMMIT_HASH_OUT(@Commit5, '-am', 'modifying row');",
  4712  		},
  4713  		Assertions: []queries.ScriptTestAssertion{
  4714  			{
  4715  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit1 and FROM_COMMIT=@Commit0;",
  4716  				Expected: []sql.Row{
  4717  					{1, 2, 3, nil, nil, nil, "added"},
  4718  					{4, 5, 6, nil, nil, nil, "added"},
  4719  				},
  4720  			},
  4721  			{
  4722  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit2 and FROM_COMMIT=@Commit1 ORDER BY to_pk;",
  4723  				Expected: []sql.Row{
  4724  					{1, 2, 0, 1, 2, 3, "modified"},
  4725  				},
  4726  			},
  4727  			{
  4728  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type FROM DOLT_COMMIT_DIFF_T WHERE TO_COMMIT=@Commit4 and FROM_COMMIT=@Commit1 ORDER BY to_pk;",
  4729  				Expected: []sql.Row{
  4730  					{1, 2, -2, 1, 2, 3, "modified"},
  4731  				},
  4732  			},
  4733  			{
  4734  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type FROM DOLT_commit_DIFF_t WHERE TO_COMMIT=@Commit5 and FROM_COMMIT=@Commit4 ORDER BY to_pk;",
  4735  				Expected: []sql.Row{
  4736  					{nil, nil, nil, 1, 2, -2, "removed"},
  4737  				},
  4738  			},
  4739  			{
  4740  				Query: "SELECT to_pk, to_c1, to_c2, from_pk, from_c1, from_c2, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit5 and FROM_COMMIT=@Commit0 ORDER BY to_pk;",
  4741  				Expected: []sql.Row{
  4742  					{4, 5, 6, nil, nil, nil, "added"},
  4743  				},
  4744  			},
  4745  		},
  4746  	},
  4747  	{
  4748  		// When a column is dropped we should see the column's value set to null in that commit
  4749  		Name: "schema modification: column drop",
  4750  		SetUpScript: []string{
  4751  			"set @Commit0 = HASHOF('HEAD');",
  4752  			"create table t (pk int primary key, c1 int, c2 int);",
  4753  			"call dolt_add('.')",
  4754  			"insert into t values (1, 2, 3), (4, 5, 6);",
  4755  			"set @Commit1 = '';",
  4756  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4757  
  4758  			"alter table t drop column c1;",
  4759  			"set @Commit2 = '';",
  4760  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');",
  4761  		},
  4762  		Assertions: []queries.ScriptTestAssertion{
  4763  			{
  4764  				Query: "SELECT to_pk, to_c2, from_pk, from_c2 FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit1 and FROM_COMMIT=@Commit0 ORDER BY to_pk;",
  4765  				Expected: []sql.Row{
  4766  					{1, 3, nil, nil},
  4767  					{4, 6, nil, nil},
  4768  				},
  4769  			},
  4770  			{
  4771  				Query: "SELECT to_pk, to_c2, from_pk, from_c2 FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit2 and FROM_COMMIT=@Commit1 ORDER BY to_pk;",
  4772  				Expected: []sql.Row{
  4773  					{1, 3, 1, 3},
  4774  					{4, 6, 4, 6},
  4775  				},
  4776  			},
  4777  		},
  4778  	},
  4779  	{
  4780  		// When a column is dropped and recreated with the same type, we expect it to be included in dolt_diff output
  4781  		Name: "schema modification: column drop, recreate with same type",
  4782  		SetUpScript: []string{
  4783  			"set @Commit0 = HASHOF('HEAD');",
  4784  			"create table t (pk int primary key, c int);",
  4785  			"call dolt_add('.')",
  4786  			"insert into t values (1, 2), (3, 4);",
  4787  			"set @Commit1 = '';",
  4788  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4789  
  4790  			"alter table t drop column c;",
  4791  			"set @Commit2 = '';",
  4792  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');",
  4793  
  4794  			"alter table t add column c int;",
  4795  			"insert into t values (100, 101);",
  4796  			"set @Commit3 = '';",
  4797  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'inserting into t');",
  4798  		},
  4799  		Assertions: []queries.ScriptTestAssertion{
  4800  			{
  4801  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit1 and FROM_COMMIT=@Commit0 ORDER BY to_pk;",
  4802  				Expected: []sql.Row{
  4803  					{1, 2, nil, nil, "added"},
  4804  					{3, 4, nil, nil, "added"},
  4805  				},
  4806  			},
  4807  			{
  4808  				Query: "SELECT to_pk, from_pk, from_c, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit2 and FROM_COMMIT=@Commit1 ORDER BY to_pk;",
  4809  				Expected: []sql.Row{
  4810  					{1, 1, 2, "modified"},
  4811  					{3, 3, 4, "modified"},
  4812  				},
  4813  			},
  4814  			{
  4815  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit3 and FROM_COMMIT=@Commit2 ORDER BY to_pk;",
  4816  				Expected: []sql.Row{
  4817  					{100, 101, nil, nil, "added"},
  4818  				},
  4819  			},
  4820  		},
  4821  	},
  4822  	{
  4823  		// When a column is dropped and another column with the same type is renamed to that name, we expect it to be included in dolt_diff output
  4824  		Name: "schema modification: column drop, rename column with same type to same name",
  4825  		SetUpScript: []string{
  4826  			"set @Commit0 = HASHOF('HEAD');",
  4827  			"create table t (pk int primary key, c1 int, c2 int);",
  4828  			"call dolt_add('.')",
  4829  			"insert into t values (1, 2, 3), (4, 5, 6);",
  4830  			"set @Commit1 = '';",
  4831  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4832  
  4833  			"alter table t drop column c1;",
  4834  			"set @Commit2 = '';",
  4835  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c1');",
  4836  
  4837  			"alter table t rename column c2 to c1;",
  4838  			"insert into t values (100, 101);",
  4839  			"set @Commit3 = '';",
  4840  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'inserting into t');",
  4841  		},
  4842  		Assertions: []queries.ScriptTestAssertion{
  4843  			{
  4844  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit1 and FROM_COMMIT=@Commit0 ORDER BY to_pk;",
  4845  				Expected: []sql.Row{
  4846  					{1, 2, nil, nil, "added"},
  4847  					{4, 5, nil, nil, "added"},
  4848  				},
  4849  			},
  4850  			{
  4851  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit2 and FROM_COMMIT=@Commit1 ORDER BY to_pk;",
  4852  				Expected: []sql.Row{
  4853  					{1, nil, 1, 2, "modified"},
  4854  					{4, nil, 4, 5, "modified"},
  4855  				},
  4856  			},
  4857  			{
  4858  				Query: "SELECT to_pk, to_c1, from_pk, from_c1, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit3 and FROM_COMMIT=@Commit2 ORDER BY to_pk;",
  4859  				Expected: []sql.Row{
  4860  					// TODO: Missing rows here see TestDiffSystemTable tests
  4861  					{100, 101, nil, nil, "added"},
  4862  				},
  4863  			},
  4864  		},
  4865  	},
  4866  
  4867  	{
  4868  		// When a column is dropped and recreated with a different type, we expect only the new column
  4869  		// to be included in dolt_commit_diff output, with previous values coerced (with any warnings reported) to the new type
  4870  		Name: "schema modification: column drop, recreate with different type that can be coerced (int -> string)",
  4871  		SetUpScript: []string{
  4872  			"set @Commit0 = HASHOF('HEAD');",
  4873  			"create table t (pk int primary key, c int);",
  4874  			"call dolt_add('.')",
  4875  			"insert into t values (1, 2), (3, 4);",
  4876  			"set @Commit1 = '';",
  4877  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4878  
  4879  			"alter table t drop column c;",
  4880  			"set @Commit2 = '';",
  4881  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');",
  4882  
  4883  			"alter table t add column c varchar(20);",
  4884  			"insert into t values (100, '101');",
  4885  			"set @Commit3 = '';",
  4886  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 're-adding column c');",
  4887  		},
  4888  		Assertions: []queries.ScriptTestAssertion{
  4889  			{
  4890  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit1 and FROM_COMMIT=@Commit0 ORDER BY to_pk;",
  4891  				Expected: []sql.Row{
  4892  					{1, "2", nil, nil, "added"},
  4893  					{3, "4", nil, nil, "added"},
  4894  				},
  4895  			},
  4896  			{
  4897  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit2 and FROM_COMMIT=@Commit1 ORDER BY to_pk;",
  4898  				Expected: []sql.Row{
  4899  					{1, nil, 1, "2", "modified"},
  4900  					{3, nil, 3, "4", "modified"},
  4901  				},
  4902  			},
  4903  			{
  4904  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit3 and FROM_COMMIT=@Commit2 ORDER BY to_pk;",
  4905  				Expected: []sql.Row{
  4906  					{100, "101", nil, nil, "added"},
  4907  				},
  4908  			},
  4909  		},
  4910  	},
  4911  	{
  4912  		Name: "schema modification: column drop, recreate with different type that can't be coerced (string -> int)",
  4913  		SetUpScript: []string{
  4914  			"set @Commit0 = HASHOF('HEAD');",
  4915  			"create table t (pk int primary key, c varchar(20));",
  4916  			"call dolt_add('.')",
  4917  			"insert into t values (1, 'two'), (3, 'four');",
  4918  			"set @Commit1 = '';",
  4919  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4920  
  4921  			"alter table t drop column c;",
  4922  			"set @Commit2 = '';",
  4923  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');",
  4924  
  4925  			"alter table t add column c int;",
  4926  			"insert into t values (100, 101);",
  4927  			"set @Commit3 = '';",
  4928  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 're-adding column c');",
  4929  		},
  4930  		Assertions: []queries.ScriptTestAssertion{
  4931  			{
  4932  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit1 and FROM_COMMIT=@Commit0 ORDER BY to_pk;",
  4933  				Expected: []sql.Row{
  4934  					{1, nil, nil, nil, "added"},
  4935  					{3, nil, nil, nil, "added"},
  4936  				},
  4937  			},
  4938  			{
  4939  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit2 and FROM_COMMIT=@Commit1 ORDER BY to_pk;",
  4940  				Expected: []sql.Row{
  4941  					{1, nil, 1, nil, "modified"},
  4942  					{3, nil, 3, nil, "modified"},
  4943  				},
  4944  			},
  4945  			{
  4946  				Query: "SELECT to_pk, to_c, from_pk, from_c, diff_type FROM DOLT_COMMIT_DIFF_t WHERE TO_COMMIT=@Commit3 and FROM_COMMIT=@Commit2 ORDER BY to_pk;",
  4947  				Expected: []sql.Row{
  4948  					{100, 101, nil, nil, "added"},
  4949  				},
  4950  			},
  4951  			{
  4952  				Query:                           "select * from dolt_commit_diff_t where to_commit=@Commit3 and from_commit=@Commit1;",
  4953  				ExpectedWarning:                 1105,
  4954  				ExpectedWarningsCount:           2,
  4955  				ExpectedWarningMessageSubstring: "unable to coerce value from field",
  4956  				SkipResultsCheck:                true,
  4957  			},
  4958  		},
  4959  	},
  4960  	{
  4961  		Name: "schema modification: primary key change",
  4962  		SetUpScript: []string{
  4963  			"create table t (pk int primary key, c1 int);",
  4964  			"call dolt_add('.')",
  4965  			"insert into t values (1, 2), (3, 4);",
  4966  			"set @Commit1 = '';",
  4967  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  4968  
  4969  			"alter table t drop primary key;",
  4970  			"insert into t values (5, 6);",
  4971  			"set @Commit2 = '';",
  4972  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping primary key');",
  4973  
  4974  			"alter table t add primary key (c1);",
  4975  			"set @Commit3 = '';",
  4976  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'adding primary key');",
  4977  
  4978  			"insert into t values (7, 8);",
  4979  			"set @Commit4 = '';",
  4980  			"CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'adding more data');",
  4981  		},
  4982  		Assertions: []queries.ScriptTestAssertion{
  4983  			{
  4984  				Query:                           "select * from dolt_commit_diff_t where from_commit=@Commit1 and to_commit=@Commit4;",
  4985  				ExpectedWarning:                 1105,
  4986  				ExpectedWarningsCount:           1,
  4987  				ExpectedWarningMessageSubstring: "cannot render full diff between commits",
  4988  				SkipResultsCheck:                true,
  4989  			},
  4990  			{
  4991  				Query:    "SELECT to_pk, to_c1, from_pk, from_c1, diff_type FROM DOLT_commit_DIFF_t where from_commit=@Commit3 and to_commit=@Commit4;",
  4992  				Expected: []sql.Row{{7, 8, nil, nil, "added"}},
  4993  			},
  4994  		},
  4995  	},
  4996  	{
  4997  		Name: "added and dropped table",
  4998  		SetUpScript: []string{
  4999  			"create table t (pk int primary key, c1 int);",
  5000  			"call dolt_add('.')",
  5001  			"insert into t values (1, 2), (3, 4);",
  5002  			"set @Commit1 = '';",
  5003  			"CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');",
  5004  
  5005  			"drop table t",
  5006  			"set @Commit2 = '';",
  5007  			"CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping table');",
  5008  
  5009  			"create table unrelated (a int primary key);",
  5010  			"set @Commit3 = '';",
  5011  			"CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-Am', 'created unrelated table');",
  5012  
  5013  			"create table t (pk int primary key, c1 int);",
  5014  			"call dolt_add('.')",
  5015  			"insert into t values (1, 2);",
  5016  			"set @Commit4 = '';",
  5017  			"CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-Am', 'recreating table t');",
  5018  		},
  5019  		Assertions: []queries.ScriptTestAssertion{
  5020  			{
  5021  				Query:                           "select * from dolt_commit_diff_t where from_commit=@Commit2 and to_commit=@Commit3;",
  5022  				ExpectedWarning:                 1105,
  5023  				ExpectedWarningsCount:           1,
  5024  				ExpectedWarningMessageSubstring: "cannot render full diff between commits",
  5025  				Expected:                        []sql.Row{},
  5026  			},
  5027  			{
  5028  				Query:                           "select * from dolt_commit_diff_t where from_commit=@Commit3 and to_commit=@Commit3;",
  5029  				ExpectedWarning:                 1105,
  5030  				ExpectedWarningsCount:           1,
  5031  				ExpectedWarningMessageSubstring: "cannot render full diff between commits",
  5032  				Expected:                        []sql.Row{},
  5033  			},
  5034  			{
  5035  				Query:    "SELECT to_pk, to_c1, from_pk, from_c1, diff_type FROM DOLT_commit_DIFF_t where from_commit=@Commit3 and to_commit=@Commit4;",
  5036  				Expected: []sql.Row{{1, 2, nil, nil, "added"}},
  5037  			},
  5038  			{
  5039  				Query:    "SELECT to_pk, to_c1, from_pk, from_c1, diff_type FROM DOLT_commit_DIFF_t where from_commit=@Commit1 and to_commit=@Commit4;",
  5040  				Expected: []sql.Row{{nil, nil, 3, 4, "removed"}},
  5041  			},
  5042  		},
  5043  	},
  5044  }
  5045  
  5046  var SchemaDiffTableFunctionScriptTests = []queries.ScriptTest{
  5047  	{
  5048  		Name: "basic schema changes",
  5049  		SetUpScript: []string{
  5050  			"create table employees (pk int primary key, name varchar(50));",
  5051  			"create table vacations (pk int primary key, name varchar(50));",
  5052  			"call dolt_add('.');",
  5053  			"set @Commit0 = '';",
  5054  			"call dolt_commit_hash_out(@Commit0, '-am', 'commit 0');",
  5055  
  5056  			"call dolt_checkout('-b', 'branch1');",
  5057  			"create table inventory (pk int primary key, name varchar(50), quantity int);",
  5058  			"drop table employees;",
  5059  			"rename table vacations to trips;",
  5060  			"call dolt_add('.');",
  5061  			"set @Commit1 = '';",
  5062  			"call dolt_commit_hash_out(@Commit1, '-am', 'commit 1');",
  5063  			"call dolt_tag('tag1');",
  5064  
  5065  			"call dolt_checkout('-b', 'branch2');",
  5066  			"alter table inventory drop column quantity, add column color varchar(10);",
  5067  			"call dolt_add('.');",
  5068  			"set @Commit2 = '';",
  5069  			"call dolt_commit_hash_out(@Commit2, '-m', 'commit 2');",
  5070  			"call dolt_tag('tag2');",
  5071  
  5072  			"call dolt_checkout('-b', 'branch3');",
  5073  			"insert into inventory values (1, 2, 3);",
  5074  			"call dolt_add('.');",
  5075  			"set @Commit3 = '';",
  5076  			"call dolt_commit_hash_out(@Commit3, '-m', 'commit 3');",
  5077  			"call dolt_tag('tag3');",
  5078  		},
  5079  		Assertions: []queries.ScriptTestAssertion{
  5080  			// Error cases
  5081  			{
  5082  				Query:          "select * from dolt_schema_diff();",
  5083  				ExpectedErrStr: "function 'dolt_schema_diff' expected 1 to 3 arguments, 0 received",
  5084  			},
  5085  			{
  5086  				Query:          "select * from dolt_schema_diff('HEAD');",
  5087  				ExpectedErrStr: "Invalid argument to dolt_schema_diff: There are less than 2 arguments present, and the first does not contain '..'",
  5088  			},
  5089  			{
  5090  				Query:          "select * from dolt_schema_diff(@Commit1);",
  5091  				ExpectedErrStr: "Invalid argument to dolt_schema_diff: There are less than 2 arguments present, and the first does not contain '..'",
  5092  			},
  5093  			{
  5094  				Query:          "select * from dolt_schema_diff('branc1');",
  5095  				ExpectedErrStr: "Invalid argument to dolt_schema_diff: There are less than 2 arguments present, and the first does not contain '..'",
  5096  			},
  5097  			{
  5098  				Query:          "select * from dolt_schema_diff('tag1');",
  5099  				ExpectedErrStr: "Invalid argument to dolt_schema_diff: There are less than 2 arguments present, and the first does not contain '..'",
  5100  			},
  5101  			{
  5102  				Query:          "select * from dolt_schema_diff('HEAD', '');",
  5103  				ExpectedErrStr: "expected strings for from and to revisions, got: HEAD, ",
  5104  			},
  5105  			{
  5106  				Query:          "select * from dolt_schema_diff('tag1', '');",
  5107  				ExpectedErrStr: "expected strings for from and to revisions, got: tag1, ",
  5108  			},
  5109  			{
  5110  				Query:          "select * from dolt_schema_diff('HEAD', 'inventory');",
  5111  				ExpectedErrStr: "branch not found: inventory",
  5112  			},
  5113  			{
  5114  				Query:          "select * from dolt_schema_diff('inventory');",
  5115  				ExpectedErrStr: "Invalid argument to dolt_schema_diff: There are less than 2 arguments present, and the first does not contain '..'",
  5116  			},
  5117  			{
  5118  				Query:          "select * from dolt_schema_diff('tag3', 'tag4');",
  5119  				ExpectedErrStr: "branch not found: tag4",
  5120  			},
  5121  			{
  5122  				Query:          "select * from dolt_schema_diff('tag3', 'tag4', 'inventory');",
  5123  				ExpectedErrStr: "branch not found: tag4",
  5124  			},
  5125  			// Empty diffs due to same refs
  5126  			{
  5127  				Query:    "select * from dolt_schema_diff('HEAD', 'HEAD');",
  5128  				Expected: []sql.Row{},
  5129  			},
  5130  			{
  5131  				Query:    "select * from dolt_schema_diff(@Commit1, @Commit1);",
  5132  				Expected: []sql.Row{},
  5133  			},
  5134  			{
  5135  				Query:    "select * from dolt_schema_diff('branch1', 'branch1');",
  5136  				Expected: []sql.Row{},
  5137  			},
  5138  			{
  5139  				Query:    "select * from dolt_schema_diff('tag1', 'tag1');",
  5140  				Expected: []sql.Row{},
  5141  			},
  5142  			// Empty diffs due to fake table
  5143  			{
  5144  				Query:    "select * from dolt_schema_diff(@Commit1, @Commit2, 'fake-table');",
  5145  				Expected: []sql.Row{},
  5146  			},
  5147  			{
  5148  				Query:    "select * from dolt_schema_diff('tag1', 'tag2', 'fake-table');",
  5149  				Expected: []sql.Row{},
  5150  			},
  5151  			{
  5152  				Query:    "select * from dolt_schema_diff('branch1', 'branch2', 'fake-table');",
  5153  				Expected: []sql.Row{},
  5154  			},
  5155  			// Empty diffs due to no changes between different commits
  5156  			{
  5157  				Query:    "select * from dolt_schema_diff(@Commit2, @Commit3);",
  5158  				Expected: []sql.Row{},
  5159  			},
  5160  			{
  5161  				Query:    "select * from dolt_schema_diff(@Commit2, @Commit3, 'inventory');",
  5162  				Expected: []sql.Row{},
  5163  			},
  5164  			{
  5165  				Query:    "select * from dolt_schema_diff('tag2', 'tag3');",
  5166  				Expected: []sql.Row{},
  5167  			},
  5168  			{
  5169  				Query:    "select * from dolt_schema_diff('tag2', 'tag3', 'inventory');",
  5170  				Expected: []sql.Row{},
  5171  			},
  5172  			{
  5173  				Query:    "select * from dolt_schema_diff('branch2', 'branch3');",
  5174  				Expected: []sql.Row{},
  5175  			},
  5176  			{
  5177  				Query:    "select * from dolt_schema_diff('branch2', 'branch3', 'inventory');",
  5178  				Expected: []sql.Row{},
  5179  			},
  5180  			// Compare diffs where between from and to where: tables are added, tables are dropped, tables are renamed
  5181  			{
  5182  				Query: "select * from dolt_schema_diff(@Commit0, @Commit1);",
  5183  				Expected: []sql.Row{
  5184  					{"employees", "", "CREATE TABLE `employees` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", ""},
  5185  					{"", "inventory", "", "CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  5186  					{"vacations", "trips", "CREATE TABLE `vacations` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", "CREATE TABLE `trips` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  5187  				},
  5188  			},
  5189  			{
  5190  				Query: "select * from dolt_schema_diff(@Commit1, @Commit0);",
  5191  				Expected: []sql.Row{
  5192  					{"inventory", "", "CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", ""},
  5193  					{"", "employees", "", "CREATE TABLE `employees` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  5194  					{"trips", "vacations", "CREATE TABLE `trips` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", "CREATE TABLE `vacations` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  5195  				},
  5196  			},
  5197  			// Compare diffs with explicit table names
  5198  			{
  5199  				Query: "select * from dolt_schema_diff(@Commit0, @Commit1, 'employees');",
  5200  				Expected: []sql.Row{
  5201  					{"employees", "", "CREATE TABLE `employees` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", ""},
  5202  				},
  5203  			},
  5204  			{
  5205  				Query: "select * from dolt_schema_diff(@Commit1, @Commit0, 'employees');",
  5206  				Expected: []sql.Row{
  5207  					{"", "employees", "", "CREATE TABLE `employees` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  5208  				},
  5209  			},
  5210  			{
  5211  				Query: "select * from dolt_schema_diff(@Commit0, @Commit1, 'inventory');",
  5212  				Expected: []sql.Row{
  5213  					{"", "inventory", "", "CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  5214  				},
  5215  			},
  5216  			{
  5217  				Query: "select * from dolt_schema_diff(@Commit1, @Commit0, 'inventory');",
  5218  				Expected: []sql.Row{
  5219  					{"inventory", "", "CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", ""},
  5220  				},
  5221  			},
  5222  			{
  5223  				Query: "select * from dolt_schema_diff(@Commit0, @Commit1, 'trips');",
  5224  				Expected: []sql.Row{
  5225  					{"vacations", "trips", "CREATE TABLE `vacations` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", "CREATE TABLE `trips` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  5226  				},
  5227  			},
  5228  			{
  5229  				Query: "select * from dolt_schema_diff(@Commit1, @Commit0, 'trips');",
  5230  				Expected: []sql.Row{
  5231  					{"trips", "vacations", "CREATE TABLE `trips` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", "CREATE TABLE `vacations` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  5232  				},
  5233  			},
  5234  			{
  5235  				Query: "select * from dolt_schema_diff(@Commit0, @Commit1, 'vacations');",
  5236  				Expected: []sql.Row{
  5237  					{"vacations", "trips", "CREATE TABLE `vacations` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", "CREATE TABLE `trips` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  5238  				},
  5239  			},
  5240  			{
  5241  				Query: "select * from dolt_schema_diff(@Commit1, @Commit0, 'vacations');",
  5242  				Expected: []sql.Row{
  5243  					{"trips", "vacations", "CREATE TABLE `trips` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", "CREATE TABLE `vacations` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"},
  5244  				},
  5245  			},
  5246  			// Compare two different commits, get expected results
  5247  			{
  5248  				Query: "select * from dolt_schema_diff(@Commit1, @Commit2);",
  5249  				Expected: []sql.Row{
  5250  					{
  5251  						"inventory",
  5252  						"inventory",
  5253  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5254  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5255  					},
  5256  				},
  5257  			},
  5258  			{
  5259  				Query: "select * from dolt_schema_diff(@Commit1, @Commit2, 'inventory');",
  5260  				Expected: []sql.Row{
  5261  					{
  5262  						"inventory",
  5263  						"inventory",
  5264  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5265  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5266  					},
  5267  				},
  5268  			},
  5269  			{
  5270  				Query: "select * from dolt_schema_diff('branch1', 'branch2');",
  5271  				Expected: []sql.Row{
  5272  					{
  5273  						"inventory",
  5274  						"inventory",
  5275  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5276  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5277  					},
  5278  				},
  5279  			},
  5280  			{
  5281  				Query: "select * from dolt_schema_diff('branch1..branch2');",
  5282  				Expected: []sql.Row{
  5283  					{
  5284  						"inventory",
  5285  						"inventory",
  5286  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5287  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5288  					},
  5289  				},
  5290  			},
  5291  			{
  5292  				Query: "select * from dolt_schema_diff('branch1...branch2');",
  5293  				Expected: []sql.Row{
  5294  					{
  5295  						"inventory",
  5296  						"inventory",
  5297  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5298  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5299  					},
  5300  				},
  5301  			},
  5302  			{
  5303  				Query: "select * from dolt_schema_diff('branch1', 'branch2', 'inventory');",
  5304  				Expected: []sql.Row{
  5305  					{
  5306  						"inventory",
  5307  						"inventory",
  5308  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5309  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5310  					},
  5311  				},
  5312  			},
  5313  			{
  5314  				Query: "select * from dolt_schema_diff('tag1', 'tag2');",
  5315  				Expected: []sql.Row{
  5316  					{
  5317  						"inventory",
  5318  						"inventory",
  5319  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5320  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5321  					},
  5322  				},
  5323  			},
  5324  			{
  5325  				Query: "select * from dolt_schema_diff('tag1..tag2');",
  5326  				Expected: []sql.Row{
  5327  					{
  5328  						"inventory",
  5329  						"inventory",
  5330  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5331  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5332  					},
  5333  				},
  5334  			},
  5335  			{
  5336  				Query: "select * from dolt_schema_diff('tag1...tag2');",
  5337  				Expected: []sql.Row{
  5338  					{
  5339  						"inventory",
  5340  						"inventory",
  5341  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5342  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5343  					},
  5344  				},
  5345  			},
  5346  			{
  5347  				Query: "select * from dolt_schema_diff('tag1', 'tag2', 'inventory');",
  5348  				Expected: []sql.Row{
  5349  					{
  5350  						"inventory",
  5351  						"inventory",
  5352  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5353  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5354  					},
  5355  				},
  5356  			},
  5357  			// Swap the order of the refs, get opposite diff
  5358  			{
  5359  				Query: "select * from dolt_schema_diff(@Commit2, @Commit1);",
  5360  				Expected: []sql.Row{
  5361  					{
  5362  						"inventory",
  5363  						"inventory",
  5364  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5365  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5366  					},
  5367  				},
  5368  			},
  5369  			{
  5370  				Query: "select * from dolt_schema_diff(@Commit2, @Commit1, 'inventory');",
  5371  				Expected: []sql.Row{
  5372  					{
  5373  						"inventory",
  5374  						"inventory",
  5375  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5376  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5377  					},
  5378  				},
  5379  			},
  5380  			{
  5381  				Query: "select * from dolt_schema_diff('branch2', 'branch1');",
  5382  				Expected: []sql.Row{
  5383  					{
  5384  						"inventory",
  5385  						"inventory",
  5386  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5387  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5388  					},
  5389  				},
  5390  			},
  5391  			{
  5392  				Query: "select * from dolt_schema_diff('branch2', 'branch1', 'inventory');",
  5393  				Expected: []sql.Row{
  5394  					{
  5395  						"inventory",
  5396  						"inventory",
  5397  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5398  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5399  					},
  5400  				},
  5401  			},
  5402  			{
  5403  				Query: "select * from dolt_schema_diff('tag2', 'tag1');",
  5404  				Expected: []sql.Row{
  5405  					{
  5406  						"inventory",
  5407  						"inventory",
  5408  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5409  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5410  					},
  5411  				},
  5412  			},
  5413  			{
  5414  				Query: "select * from dolt_schema_diff('tag2', 'tag1', 'inventory');",
  5415  				Expected: []sql.Row{
  5416  					{
  5417  						"inventory",
  5418  						"inventory",
  5419  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `color` varchar(10),\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5420  						"CREATE TABLE `inventory` (\n  `pk` int NOT NULL,\n  `name` varchar(50),\n  `quantity` int,\n  PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
  5421  					},
  5422  				},
  5423  			},
  5424  		},
  5425  	},
  5426  	{
  5427  		Name: "prepared table functions",
  5428  		SetUpScript: []string{
  5429  			"create table t1 (a int primary key)",
  5430  			"insert into t1 values (0), (1)",
  5431  			"call dolt_add('.');",
  5432  			"set @Commit0 = '';",
  5433  			"call dolt_commit_hash_out(@Commit0, '-am', 'commit 0');",
  5434  			//
  5435  			"alter table t1 add column b int default 1",
  5436  			"call dolt_add('.');",
  5437  			"set @Commit1 = '';",
  5438  			"call dolt_commit_hash_out(@Commit1, '-am', 'commit 1');",
  5439  			//
  5440  			"create table t2 (a int primary key)",
  5441  			"insert into t2 values (0), (1)",
  5442  			"insert into t1 values (2,2), (3,2)",
  5443  			"call dolt_add('.');",
  5444  			"set @Commit2 = '';",
  5445  			"call dolt_commit_hash_out(@Commit2, '-am', 'commit 2');",
  5446  			//
  5447  			"prepare sch_diff from 'select count(*) from dolt_schema_diff(?,?,?)'",
  5448  			"prepare diff_stat from 'select count(*) from dolt_diff_stat(?,?,?)'",
  5449  			"prepare diff_sum from 'select count(*) from dolt_diff_summary(?,?,?)'",
  5450  			//"prepare table_diff from 'select * from dolt_diff(?,?,?)'",
  5451  			"prepare patch from 'select count(*) from dolt_schema_diff(?,?,?)'",
  5452  		},
  5453  		Assertions: []queries.ScriptTestAssertion{
  5454  			{
  5455  				Query: "set @t1_name = 't1';",
  5456  			},
  5457  			{
  5458  				Query:    "execute sch_diff using @Commit0, @Commit1, @t1_name",
  5459  				Expected: []sql.Row{{1}},
  5460  			},
  5461  			{
  5462  				Query:    "execute diff_stat using @Commit1, @Commit2, @t1_name",
  5463  				Expected: []sql.Row{{1}},
  5464  			},
  5465  			{
  5466  				Query:    "execute diff_sum using @Commit1, @Commit2, @t1_name",
  5467  				Expected: []sql.Row{{1}},
  5468  			},
  5469  			//{
  5470  			//	Query:    "execute table_diff using @Commit2, @Commit2, @t1_name",
  5471  			//	Expected: []sql.Row{},
  5472  			//},
  5473  			{
  5474  				Query:    "execute patch using @Commit0, @Commit1, @t1_name",
  5475  				Expected: []sql.Row{{1}},
  5476  			},
  5477  		},
  5478  	},
  5479  }
  5480  
  5481  var DoltDatabaseCollationScriptTests = []queries.ScriptTest{
  5482  	{
  5483  		Name:        "can't use __DATABASE__ prefix in table names",
  5484  		SetUpScript: []string{},
  5485  		Assertions: []queries.ScriptTestAssertion{
  5486  			{
  5487  				Query:          "create table __DATABASE__t(i int);",
  5488  				ExpectedErrStr: "Invalid table name __DATABASE__t. Table names beginning with `__DATABASE__` are reserved for internal use",
  5489  			},
  5490  		},
  5491  	},
  5492  	{
  5493  		Name:        "db collation change with dolt_add('.')",
  5494  		SetUpScript: []string{},
  5495  		Assertions: []queries.ScriptTestAssertion{
  5496  			{
  5497  				Query:    "select * from dolt_status",
  5498  				Expected: []sql.Row{},
  5499  			},
  5500  			{
  5501  				Query:    "select commit_hash, table_name, data_change, schema_change from dolt_diff",
  5502  				Expected: []sql.Row{},
  5503  			},
  5504  
  5505  			{
  5506  				Query: "alter database mydb collate utf8mb4_spanish_ci",
  5507  				Expected: []sql.Row{
  5508  					{gmstypes.NewOkResult(1)},
  5509  				},
  5510  			},
  5511  			{
  5512  				Query: "select * from dolt_status",
  5513  				Expected: []sql.Row{
  5514  					{"__DATABASE__mydb", false, "modified"},
  5515  				},
  5516  			},
  5517  			{
  5518  				Query: "select commit_hash, table_name, data_change, schema_change from dolt_diff",
  5519  				Expected: []sql.Row{
  5520  					{"WORKING", "__DATABASE__mydb", false, true},
  5521  				},
  5522  			},
  5523  
  5524  			{
  5525  				Query: "call dolt_add('.')",
  5526  				Expected: []sql.Row{
  5527  					{0},
  5528  				},
  5529  			},
  5530  			{
  5531  				Query: "select * from dolt_status",
  5532  				Expected: []sql.Row{
  5533  					{"__DATABASE__mydb", true, "modified"},
  5534  				},
  5535  			},
  5536  			{
  5537  				Query: "select commit_hash, table_name, data_change, schema_change from dolt_diff",
  5538  				Expected: []sql.Row{
  5539  					{"STAGED", "__DATABASE__mydb", false, true},
  5540  				},
  5541  			},
  5542  			{
  5543  				Query: "select message from dolt_log",
  5544  				Expected: []sql.Row{
  5545  					{"checkpoint enginetest database mydb"},
  5546  					{"Initialize data repository"},
  5547  				},
  5548  			},
  5549  
  5550  			{
  5551  				Query:            "call dolt_commit('-m', 'db collation changed')",
  5552  				SkipResultsCheck: true,
  5553  			},
  5554  			{
  5555  				Query:    "select * from dolt_status",
  5556  				Expected: []sql.Row{},
  5557  			},
  5558  			{
  5559  				Query: "select table_name, data_change, schema_change from dolt_diff",
  5560  				Expected: []sql.Row{
  5561  					{"__DATABASE__mydb", false, true},
  5562  				},
  5563  			},
  5564  			{
  5565  				Query: "select message from dolt_log",
  5566  				Expected: []sql.Row{
  5567  					{"db collation changed"},
  5568  					{"checkpoint enginetest database mydb"},
  5569  					{"Initialize data repository"},
  5570  				},
  5571  			},
  5572  		},
  5573  	},
  5574  	{
  5575  		Name:        "db collation change with dolt_add('__DATABASE__mydb')",
  5576  		SetUpScript: []string{},
  5577  		Assertions: []queries.ScriptTestAssertion{
  5578  			{
  5579  				Query:    "select * from dolt_status",
  5580  				Expected: []sql.Row{},
  5581  			},
  5582  			{
  5583  				Query:    "select commit_hash, table_name, data_change, schema_change from dolt_diff",
  5584  				Expected: []sql.Row{},
  5585  			},
  5586  
  5587  			{
  5588  				Query: "alter database mydb collate utf8mb4_spanish_ci",
  5589  				Expected: []sql.Row{
  5590  					{gmstypes.NewOkResult(1)},
  5591  				},
  5592  			},
  5593  			{
  5594  				Query: "select * from dolt_status",
  5595  				Expected: []sql.Row{
  5596  					{"__DATABASE__mydb", false, "modified"},
  5597  				},
  5598  			},
  5599  			{
  5600  				Query: "select commit_hash, table_name, data_change, schema_change from dolt_diff",
  5601  				Expected: []sql.Row{
  5602  					{"WORKING", "__DATABASE__mydb", false, true},
  5603  				},
  5604  			},
  5605  
  5606  			{
  5607  				Query: "call dolt_add('__DATABASE__mydb')",
  5608  				Expected: []sql.Row{
  5609  					{0},
  5610  				},
  5611  			},
  5612  			{
  5613  				Query: "select * from dolt_status",
  5614  				Expected: []sql.Row{
  5615  					{"__DATABASE__mydb", true, "modified"},
  5616  				},
  5617  			},
  5618  			{
  5619  				Query: "select commit_hash, table_name, data_change, schema_change from dolt_diff",
  5620  				Expected: []sql.Row{
  5621  					{"STAGED", "__DATABASE__mydb", false, true},
  5622  				},
  5623  			},
  5624  			{
  5625  				Query: "select message from dolt_log",
  5626  				Expected: []sql.Row{
  5627  					{"checkpoint enginetest database mydb"},
  5628  					{"Initialize data repository"},
  5629  				},
  5630  			},
  5631  
  5632  			{
  5633  				Query:            "call dolt_commit('-m', 'db collation changed')",
  5634  				SkipResultsCheck: true,
  5635  			},
  5636  			{
  5637  				Query:    "select * from dolt_status",
  5638  				Expected: []sql.Row{},
  5639  			},
  5640  			{
  5641  				Query: "select table_name, data_change, schema_change from dolt_diff",
  5642  				Expected: []sql.Row{
  5643  					{"__DATABASE__mydb", false, true},
  5644  				},
  5645  			},
  5646  			{
  5647  				Query: "select message from dolt_log",
  5648  				Expected: []sql.Row{
  5649  					{"db collation changed"},
  5650  					{"checkpoint enginetest database mydb"},
  5651  					{"Initialize data repository"},
  5652  				},
  5653  			},
  5654  		},
  5655  	},
  5656  	{
  5657  		Name:        "db collation change with dolt_commit('-Am', '')",
  5658  		SetUpScript: []string{},
  5659  		Assertions: []queries.ScriptTestAssertion{
  5660  			{
  5661  				Query:    "select * from dolt_status",
  5662  				Expected: []sql.Row{},
  5663  			},
  5664  			{
  5665  				Query:    "select commit_hash, table_name, data_change, schema_change from dolt_diff",
  5666  				Expected: []sql.Row{},
  5667  			},
  5668  
  5669  			{
  5670  				Query: "alter database mydb collate utf8mb4_spanish_ci",
  5671  				Expected: []sql.Row{
  5672  					{gmstypes.NewOkResult(1)},
  5673  				},
  5674  			},
  5675  			{
  5676  				Query: "select * from dolt_status",
  5677  				Expected: []sql.Row{
  5678  					{"__DATABASE__mydb", false, "modified"},
  5679  				},
  5680  			},
  5681  			{
  5682  				Query: "select commit_hash, table_name, data_change, schema_change from dolt_diff",
  5683  				Expected: []sql.Row{
  5684  					{"WORKING", "__DATABASE__mydb", false, true},
  5685  				},
  5686  			},
  5687  			{
  5688  				Query: "select message from dolt_log",
  5689  				Expected: []sql.Row{
  5690  					{"checkpoint enginetest database mydb"},
  5691  					{"Initialize data repository"},
  5692  				},
  5693  			},
  5694  
  5695  			{
  5696  				Query:            "call dolt_commit('-Am', 'db collation changed')",
  5697  				SkipResultsCheck: true,
  5698  			},
  5699  			{
  5700  				Query:    "select * from dolt_status",
  5701  				Expected: []sql.Row{},
  5702  			},
  5703  			{
  5704  				Query: "select table_name, data_change, schema_change from dolt_diff",
  5705  				Expected: []sql.Row{
  5706  					{"__DATABASE__mydb", false, true},
  5707  				},
  5708  			},
  5709  			{
  5710  				Query: "select message from dolt_log",
  5711  				Expected: []sql.Row{
  5712  					{"db collation changed"},
  5713  					{"checkpoint enginetest database mydb"},
  5714  					{"Initialize data repository"},
  5715  				},
  5716  			},
  5717  		},
  5718  	},
  5719  	{
  5720  		Name: "db collation hard reset",
  5721  		SetUpScript: []string{
  5722  			"alter database mydb collate utf8mb4_spanish_ci",
  5723  		},
  5724  		Assertions: []queries.ScriptTestAssertion{
  5725  			{
  5726  				Query: "select * from dolt_status;",
  5727  				Expected: []sql.Row{
  5728  					{"__DATABASE__mydb", false, "modified"},
  5729  				},
  5730  			},
  5731  			{
  5732  				Query: "call dolt_reset('--hard');",
  5733  				Expected: []sql.Row{
  5734  					{0},
  5735  				},
  5736  			},
  5737  			{
  5738  				Query:    "select * from dolt_status;",
  5739  				Expected: []sql.Row{},
  5740  			},
  5741  		},
  5742  	},
  5743  	{
  5744  		Name: "db collation with branch",
  5745  		SetUpScript: []string{
  5746  			"call dolt_checkout('-b', 'other');",
  5747  			"alter database mydb collate utf8mb4_spanish_ci;",
  5748  			"call dolt_commit('-Am', 'db collation');",
  5749  		},
  5750  		Assertions: []queries.ScriptTestAssertion{
  5751  			{
  5752  				Query: "show create database mydb;",
  5753  				Expected: []sql.Row{
  5754  					{"mydb", "CREATE DATABASE `mydb` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_spanish_ci */"},
  5755  				},
  5756  			},
  5757  			{
  5758  				Query:            "call dolt_checkout('main');",
  5759  				SkipResultsCheck: true,
  5760  			},
  5761  			{
  5762  				Query: "show create database mydb;",
  5763  				Expected: []sql.Row{
  5764  					{"mydb", "CREATE DATABASE `mydb` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin */"},
  5765  				},
  5766  			},
  5767  		},
  5768  	},
  5769  	{
  5770  		Name: "db collation with ff merge",
  5771  		SetUpScript: []string{
  5772  			"call dolt_checkout('-b', 'other');",
  5773  			"alter database mydb collate utf8mb4_spanish_ci;",
  5774  			"call dolt_commit('-Am', 'db collation');",
  5775  			"call dolt_checkout('main');",
  5776  		},
  5777  		Assertions: []queries.ScriptTestAssertion{
  5778  			{
  5779  				Query: "show create database mydb;",
  5780  				Expected: []sql.Row{
  5781  					{"mydb", "CREATE DATABASE `mydb` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin */"},
  5782  				},
  5783  			},
  5784  			{
  5785  				Query:            "call dolt_merge('other');",
  5786  				SkipResultsCheck: true,
  5787  			},
  5788  			{
  5789  				Query: "show create database mydb;",
  5790  				Expected: []sql.Row{
  5791  					{"mydb", "CREATE DATABASE `mydb` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_spanish_ci */"},
  5792  				},
  5793  			},
  5794  		},
  5795  	},
  5796  	{
  5797  		Name: "db collation merge conflict",
  5798  		SetUpScript: []string{
  5799  			"call dolt_branch('other');",
  5800  			"alter database mydb collate utf8mb4_spanish_ci;",
  5801  			"call dolt_commit('-Am', 'main collation');",
  5802  			"call dolt_checkout('other');",
  5803  			"alter database mydb collate utf8mb4_danish_ci;",
  5804  			"call dolt_commit('-Am', 'main collation');",
  5805  		},
  5806  		Assertions: []queries.ScriptTestAssertion{
  5807  			{
  5808  				Query:          "call dolt_merge('main');",
  5809  				ExpectedErrStr: "database collation conflict, please resolve manually. ours: utf8mb4_danish_ci, theirs: utf8mb4_spanish_ci",
  5810  			},
  5811  		},
  5812  	},
  5813  }
  5814  
  5815  type systabScript struct {
  5816  	name    string
  5817  	setup   []string
  5818  	queries []systabQuery
  5819  }
  5820  
  5821  type systabQuery struct {
  5822  	query string
  5823  	exp   []sql.Row
  5824  	skip  bool
  5825  }
  5826  
  5827  var systabSetup = []string{
  5828  	"create table xy (x int primary key, y varchar(20));",
  5829  	"insert into xy values (0, 'row 0'), (1, 'row 1'), (2, 'row 2'), (3, 'row 3'), (4, 'row 4');",
  5830  	"call dolt_add('.');",
  5831  	"call dolt_commit('-m', 'commit 0');",
  5832  	"update xy set y = y+1 where x < 10",
  5833  	"insert into xy values (20, 'row 20'), (21, 'row 21'), (22, 'row 22'), (23, 'row 23'), (24, 'row 24');",
  5834  	"call dolt_add('.');",
  5835  	"call dolt_commit('-m', 'commit 1');",
  5836  	"update xy set y = y+1 where x > 10 and x < 30",
  5837  	"insert into xy values (40, 'row 40'), (41, 'row 41'), (42, 'row 42'), (43, 'row 43'), (44, 'row 44');",
  5838  	"call dolt_add('.');",
  5839  	"call dolt_commit('-m', 'commit 2');",
  5840  	"update xy set y = y+1 where x > 30 and x < 50",
  5841  	"insert into xy values (60, 'row 60'), (61, 'row 61'), (62, 'row 62'), (63, 'row 63'), (64, 'row 64');",
  5842  	"call dolt_add('.');",
  5843  	"call dolt_commit('-m', 'commit 3');",
  5844  	"update xy set y = y+1 where x > 50 and x < 70",
  5845  	"insert into xy values (80, 'row 80'), (81, 'row 81'), (82, 'row 82'), (83, 'row 83'), (84, 'row 84');",
  5846  	"call dolt_add('.');",
  5847  	"call dolt_commit('-m', 'commit 4');",
  5848  }
  5849  
  5850  var SystemTableIndexTests = []systabScript{
  5851  	{
  5852  		name: "systab benchmarks",
  5853  		setup: append(systabSetup,
  5854  			"set @commit = (select commit_hash from dolt_log where message = 'commit 2');",
  5855  		),
  5856  		queries: []systabQuery{
  5857  			{
  5858  				query: "select from_x, to_x from dolt_diff_xy where to_commit = @commit;",
  5859  				exp:   []sql.Row{{20, 20}, {21, 21}, {22, 22}, {23, 23}, {24, 24}, {nil, 40}, {nil, 41}, {nil, 42}, {nil, 43}, {nil, 44}},
  5860  			},
  5861  			{
  5862  				query: "select from_x, to_x from dolt_diff_xy where from_commit = @commit;",
  5863  				exp:   []sql.Row{{40, 40}, {41, 41}, {42, 42}, {43, 43}, {44, 44}, {nil, 60}, {nil, 61}, {nil, 62}, {nil, 63}, {nil, 64}},
  5864  			},
  5865  			{
  5866  				query: "select count(*) from dolt_diff where commit_hash = @commit;",
  5867  				exp:   []sql.Row{{1}},
  5868  			},
  5869  			{
  5870  				query: "select count(*) from dolt_history_xy where commit_hash = @commit;",
  5871  				exp:   []sql.Row{{15}},
  5872  			},
  5873  			{
  5874  				query: "select count(*) from dolt_log where commit_hash = @commit;",
  5875  				exp:   []sql.Row{{1}},
  5876  			},
  5877  			{
  5878  				query: "select count(*) from dolt_commits where commit_hash = @commit;",
  5879  				exp:   []sql.Row{{1}},
  5880  			},
  5881  			{
  5882  				query: "select count(*) from dolt_commit_ancestors where commit_hash = @commit;",
  5883  				exp:   []sql.Row{{1}},
  5884  			},
  5885  			{
  5886  				query: "select count(*) from dolt_diff_xy join dolt_log on commit_hash = to_commit",
  5887  				exp:   []sql.Row{{45}},
  5888  			},
  5889  			{
  5890  				query: "select count(*) from dolt_diff_xy join dolt_log on commit_hash = from_commit",
  5891  				exp:   []sql.Row{{45}},
  5892  			},
  5893  			{
  5894  				query: "select count(*) from dolt_blame_xy",
  5895  				exp:   []sql.Row{{25}},
  5896  			},
  5897  			{
  5898  				query: `SELECT count(*)
  5899             FROM dolt_commits as cm
  5900             JOIN dolt_commit_ancestors as an
  5901             ON cm.commit_hash = an.parent_hash
  5902             ORDER BY cm.date, cm.message asc`,
  5903  				exp: []sql.Row{{5}},
  5904  			},
  5905  		},
  5906  	},
  5907  	{
  5908  		name: "required index lookup in join",
  5909  		setup: append(systabSetup,
  5910  			"set @tag_head = hashof('main^');",
  5911  			"call dolt_tag('t1', concat(@tag_head, '^'));",
  5912  		),
  5913  		queries: []systabQuery{
  5914  			{
  5915  				query: `
  5916  select /*+ HASH_JOIN(t,cd) */ distinct t.tag_name
  5917  from dolt_tags t
  5918  left join dolt_commit_diff_xy cd
  5919      on cd.to_commit = t.tag_name and
  5920         cd.from_commit = concat(t.tag_name, '^')`,
  5921  				exp: []sql.Row{{"t1"}},
  5922  			},
  5923  		},
  5924  	},
  5925  	{
  5926  		name: "commit indexing edge cases",
  5927  		setup: append(systabSetup,
  5928  			"call dolt_checkout('-b', 'feat');",
  5929  			"call dolt_commit('--allow-empty', '-m', 'feat commit 1');",
  5930  			"call dolt_commit('--allow-empty', '-m', 'feat commit 2');",
  5931  			"call dolt_checkout('main');",
  5932  			"update xy set y = y+1 where x > 70 and x < 90;",
  5933  			"set @commit = (select commit_hash from dolt_log where message = 'commit 1');",
  5934  			"set @root_commit = (select commit_hash from dolt_log where message = 'Initialize data repository');",
  5935  			"set @feat_head = hashof('feat');",
  5936  			"set @feat_head1 = hashof('feat~');",
  5937  		),
  5938  		queries: []systabQuery{
  5939  			{
  5940  				query: "select from_x, to_x from dolt_diff_xy where to_commit = 'WORKING';",
  5941  				exp:   []sql.Row{{80, 80}, {81, 81}, {82, 82}, {83, 83}, {84, 84}},
  5942  			},
  5943  			{
  5944  				query: "select * from dolt_diff_xy where from_commit = @feat_head1;",
  5945  				exp:   []sql.Row{},
  5946  			},
  5947  			{
  5948  				query: "select * from dolt_diff_xy where from_commit = 'WORKING';",
  5949  				exp:   []sql.Row{},
  5950  			},
  5951  			{
  5952  				query: "select count(*) from dolt_diff where commit_hash = 'WORKING';",
  5953  				exp:   []sql.Row{{1}},
  5954  			},
  5955  			{
  5956  				query: "select count(*) from dolt_history_xy where commit_hash = 'WORKING';",
  5957  				exp:   []sql.Row{{0}},
  5958  			},
  5959  			{
  5960  				query: "select count(*) from dolt_commit_ancestors where commit_hash = 'WORKING';",
  5961  				exp:   []sql.Row{{0}},
  5962  			},
  5963  			{
  5964  				query: "select sum(to_x) from dolt_diff_xy where to_commit in (@commit, 'WORKING');",
  5965  				exp:   []sql.Row{{530.0}},
  5966  			},
  5967  			{
  5968  				// TODO from_commit optimization
  5969  				query: "select sum(to_x) from dolt_diff_xy where from_commit in (@commit, 'WORKING');",
  5970  				exp:   []sql.Row{{320.0}},
  5971  			},
  5972  			{
  5973  				query: "select count(*) from dolt_diff where commit_hash in (@commit, 'WORKING');",
  5974  				exp:   []sql.Row{{2}},
  5975  			},
  5976  			{
  5977  				query: "select sum(x) from dolt_history_xy where commit_hash in (@commit, 'WORKING');",
  5978  				exp:   []sql.Row{{120.0}},
  5979  			},
  5980  			{
  5981  				// init commit has nil ancestor
  5982  				query: "select count(*) from dolt_commit_ancestors where commit_hash in (@commit, @root_commit);",
  5983  				exp:   []sql.Row{{2}},
  5984  			},
  5985  			{
  5986  				query: "select count(*) from dolt_log where commit_hash in (@commit, @root_commit);",
  5987  				exp:   []sql.Row{{2}},
  5988  			},
  5989  			{
  5990  				// log table cannot access commits is feature branch
  5991  				query: "select count(*) from dolt_log where commit_hash = @feat_head;",
  5992  				exp:   []sql.Row{{0}},
  5993  			},
  5994  			{
  5995  				// commit table can access all commits
  5996  				query: "select count(*) from dolt_commits where commit_hash = @feat_head;",
  5997  				exp:   []sql.Row{{1}},
  5998  			},
  5999  			{
  6000  				query: "select count(*) from dolt_commits where commit_hash in (@commit, @root_commit);",
  6001  				exp:   []sql.Row{{2}},
  6002  			},
  6003  			// unknown
  6004  			{
  6005  				query: "select from_x, to_x from dolt_diff_xy where to_commit = 'unknown';",
  6006  				exp:   []sql.Row{},
  6007  			},
  6008  			{
  6009  				query: "select * from dolt_diff_xy where from_commit = 'unknown';",
  6010  				exp:   []sql.Row{},
  6011  			},
  6012  			{
  6013  				query: "select * from dolt_diff where commit_hash = 'unknown';",
  6014  				exp:   []sql.Row{},
  6015  			},
  6016  			{
  6017  				query: "select * from dolt_history_xy where commit_hash = 'unknown';",
  6018  				exp:   []sql.Row{},
  6019  			},
  6020  			{
  6021  				query: "select * from dolt_commit_ancestors where commit_hash = 'unknown';",
  6022  				exp:   []sql.Row{},
  6023  			},
  6024  		},
  6025  	},
  6026  	{
  6027  		name: "empty log table",
  6028  		setup: []string{
  6029  			"create table xy (x int primary key, y int)",
  6030  		},
  6031  		queries: []systabQuery{
  6032  			{
  6033  				query: "select count(*) from dolt_log as dc join dolt_commit_ancestors as dca on dc.commit_hash = dca.commit_hash;",
  6034  				exp:   []sql.Row{{1}},
  6035  			},
  6036  		},
  6037  	},
  6038  	{
  6039  		name: "from_commit at multiple heights, choose highest",
  6040  		setup: []string{
  6041  			"create table x (x int primary key)",
  6042  			"call dolt_add('.');",
  6043  			"call dolt_commit_hash_out(@m1h1, '-am', 'main 1');",
  6044  			"insert into x values (1),(2);",
  6045  			"call dolt_commit_hash_out(@m2h2, '-am', 'main 2');",
  6046  			"call dolt_checkout('-b', 'other');",
  6047  			"call dolt_reset('--hard', @m1h1);",
  6048  			"insert into x values (3),(4);",
  6049  			"call dolt_commit_hash_out(@o1h2, '-am', 'other 1');",
  6050  			"insert into x values (5),(6);",
  6051  			"call dolt_commit_hash_out(@o2h3, '-am', 'other 2');",
  6052  			"call dolt_merge('main');",
  6053  			"set @o3h4 = hashof('head~');",
  6054  			"call dolt_checkout('main');",
  6055  			"insert into x values (7),(8);",
  6056  			"call dolt_commit_hash_out(@m32h3, '-am', 'main 3');",
  6057  			"call dolt_merge('other');",
  6058  			"set @m4h5 = hashof('head~');",
  6059  		},
  6060  		queries: []systabQuery{
  6061  			{
  6062  				query: "select count(*) from dolt_diff_x where from_commit = @m2h2",
  6063  				exp:   []sql.Row{{4}},
  6064  			},
  6065  		},
  6066  	},
  6067  }
  6068  
  6069  var QueryDiffTableScriptTests = []queries.ScriptTest{
  6070  	{
  6071  		Name: "basic query diff tests",
  6072  		SetUpScript: []string{
  6073  			"create table t (i int primary key, j int);",
  6074  			"insert into t values (1, 1), (2, 2), (3, 3);",
  6075  			"create table tt (i int primary key, j int);",
  6076  			"insert into tt values (10, 10), (20, 20), (30, 30);",
  6077  			"call dolt_add('.');",
  6078  			"call dolt_commit('-m', 'first');",
  6079  			"call dolt_branch('other');",
  6080  			"update t set j = 10 where i = 2;",
  6081  			"delete from t where i = 3;",
  6082  			"insert into t values (4, 4);",
  6083  			"call dolt_add('.');",
  6084  			"call dolt_commit('-m', 'second');",
  6085  		},
  6086  		Assertions: []queries.ScriptTestAssertion{
  6087  			{
  6088  				Query:          "select * from dolt_query_diff();",
  6089  				ExpectedErrStr: "function 'dolt_query_diff' expected 2 arguments, 0 received",
  6090  			},
  6091  			{
  6092  				Query:          "select * from dolt_query_diff('selectsyntaxerror', 'selectsyntaxerror');",
  6093  				ExpectedErrStr: "syntax error at position 18 near 'selectsyntaxerror'",
  6094  			},
  6095  			{
  6096  				Query:          "select * from dolt_query_diff('', '');",
  6097  				ExpectedErrStr: "query must be a SELECT statement",
  6098  			},
  6099  			{
  6100  				Query:          "select * from dolt_query_diff('create table tt (i int)', 'create table ttt (j int)');",
  6101  				ExpectedErrStr: "query must be a SELECT statement",
  6102  			},
  6103  			{
  6104  				Query:          "select * from dolt_query_diff('select * from missingtable', '');",
  6105  				ExpectedErrStr: "table not found: missingtable",
  6106  			},
  6107  			{
  6108  				Query: "select * from dolt_query_diff('select * from t as of other', 'select * from t as of head');",
  6109  				Expected: []sql.Row{
  6110  					{2, 2, 2, 10, "modified"},
  6111  					{3, 3, nil, nil, "deleted"},
  6112  					{nil, nil, 4, 4, "added"},
  6113  				},
  6114  			},
  6115  			{
  6116  				Query: "select * from dolt_query_diff('select * from t as of head', 'select * from t as of other');",
  6117  				Expected: []sql.Row{
  6118  					{2, 10, 2, 2, "modified"},
  6119  					{nil, nil, 3, 3, "added"},
  6120  					{4, 4, nil, nil, "deleted"},
  6121  				},
  6122  			},
  6123  			{
  6124  				Query: "select * from dolt_query_diff('select * from t as of other where i = 2', 'select * from t as of head where i = 2');",
  6125  				Expected: []sql.Row{
  6126  					{2, 2, 2, 10, "modified"},
  6127  				},
  6128  			},
  6129  			{
  6130  				Query: "select * from dolt_query_diff('select * from t as of other where i < 2', 'select * from t as of head where i > 2');",
  6131  				Expected: []sql.Row{
  6132  					{1, 1, nil, nil, "deleted"},
  6133  					{nil, nil, 4, 4, "added"},
  6134  				},
  6135  			},
  6136  			{
  6137  				Query: "select * from dolt_query_diff('select * from t', 'select * from tt');",
  6138  				Expected: []sql.Row{
  6139  					{1, 1, nil, nil, "deleted"},
  6140  					{2, 10, nil, nil, "deleted"},
  6141  					{4, 4, nil, nil, "deleted"},
  6142  					{nil, nil, 10, 10, "added"},
  6143  					{nil, nil, 20, 20, "added"},
  6144  					{nil, nil, 30, 30, "added"},
  6145  				},
  6146  			},
  6147  		},
  6148  	},
  6149  }