github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/libraries/doltcore/sqle/enginetest/dolt_engine_test.go (about) 1 // Copyright 2020 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 "testing" 19 20 "github.com/dolthub/go-mysql-server/enginetest" 21 "github.com/dolthub/go-mysql-server/sql" 22 23 "github.com/dolthub/dolt/go/libraries/doltcore/sqle" 24 ) 25 26 func init() { 27 sqle.MinRowsPerPartition = 2 28 } 29 30 func TestQueries(t *testing.T) { 31 t.Run("no transactions", func(t *testing.T) { 32 enginetest.TestQueries(t, newDoltHarness(t)) 33 }) 34 t.Run("with transactions", func(t *testing.T) { 35 enginetest.TestQueries(t, newDoltHarness(t).withTransactionsEnabled(true)) 36 }) 37 } 38 39 func TestSingleQuery(t *testing.T) { 40 t.Skip() 41 42 var test enginetest.QueryTest 43 test = enginetest.QueryTest{ 44 Query: `SELECT 45 myTable.i, 46 (SELECT 47 dolt_commit_diff_mytable.diff_type 48 FROM 49 dolt_commit_diff_mytable 50 WHERE ( 51 dolt_commit_diff_mytable.from_commit = 'abc' AND 52 dolt_commit_diff_mytable.to_commit = 'abc' AND 53 dolt_commit_diff_mytable.to_i = myTable.i -- extra filter clause 54 )) AS diff_type 55 FROM myTable`, 56 Expected: []sql.Row{}, 57 } 58 59 harness := newDoltHarness(t) 60 engine := enginetest.NewEngine(t, harness) 61 engine.Analyzer.Debug = true 62 engine.Analyzer.Verbose = true 63 64 enginetest.TestQuery(t, harness, engine, test.Query, test.Expected, test.ExpectedColumns, test.Bindings) 65 } 66 67 // Convenience test for debugging a single query. Unskip and set to the desired query. 68 func TestSingleScript(t *testing.T) { 69 t.Skip() 70 71 var scripts = []enginetest.ScriptTest{ 72 { 73 // All DECLARE statements are only allowed under BEGIN/END blocks 74 Name: "Top-level DECLARE statements", 75 Assertions: []enginetest.ScriptTestAssertion{ 76 { 77 Query: "select 1+1", 78 Expected: []sql.Row{{2}}, 79 }, 80 }, 81 }, 82 { 83 Name: "last_insert_id() behavior", 84 SetUpScript: []string{ 85 "create table a (x int primary key, y int)", 86 }, 87 Assertions: []enginetest.ScriptTestAssertion{}, 88 }, 89 } 90 91 harness := newDoltHarness(t) 92 for _, test := range scripts { 93 engine := enginetest.NewEngine(t, harness) 94 engine.Analyzer.Debug = true 95 engine.Analyzer.Verbose = true 96 97 enginetest.TestScriptWithEngine(t, engine, harness, test) 98 } 99 } 100 101 func TestVersionedQueries(t *testing.T) { 102 t.Run("no transactions", func(t *testing.T) { 103 enginetest.TestVersionedQueries(t, newDoltHarness(t)) 104 }) 105 t.Run("with transactions", func(t *testing.T) { 106 enginetest.TestVersionedQueries(t, newDoltHarness(t).withTransactionsEnabled(true)) 107 }) 108 } 109 110 // Tests of choosing the correct execution plan independent of result correctness. Mostly useful for confirming that 111 // the right indexes are being used for joining tables. 112 func TestQueryPlans(t *testing.T) { 113 // Dolt supports partial keys, so the index matched is different for some plans 114 // TODO: Fix these differences by implementing partial key matching in the memory tables, or the engine itself 115 skipped := []string{ 116 "SELECT pk,pk1,pk2 FROM one_pk LEFT JOIN two_pk ON pk=pk1", 117 "SELECT pk,pk1,pk2 FROM one_pk JOIN two_pk ON pk=pk1", 118 "SELECT one_pk.c5,pk1,pk2 FROM one_pk JOIN two_pk ON pk=pk1 ORDER BY 1,2,3", 119 "SELECT opk.c5,pk1,pk2 FROM one_pk opk JOIN two_pk tpk ON opk.pk=tpk.pk1 ORDER BY 1,2,3", 120 "SELECT opk.c5,pk1,pk2 FROM one_pk opk JOIN two_pk tpk ON pk=pk1 ORDER BY 1,2,3", 121 "SELECT pk,pk1,pk2 FROM one_pk LEFT JOIN two_pk ON pk=pk1 ORDER BY 1,2,3", 122 "SELECT pk,pk1,pk2 FROM one_pk t1, two_pk t2 WHERE pk=1 AND pk2=1 AND pk1=1 ORDER BY 1,2", 123 } 124 125 // Parallelism introduces Exchange nodes into the query plans, so disable. 126 // TODO: exchange nodes should really only be part of the explain plan under certain debug settings 127 enginetest.TestQueryPlans(t, newDoltHarness(t).WithParallelism(1).WithSkippedQueries(skipped)) 128 } 129 130 func TestQueryErrors(t *testing.T) { 131 t.Run("no transactions", func(t *testing.T) { 132 enginetest.TestQueryErrors(t, newDoltHarness(t)) 133 }) 134 t.Run("with transactions", func(t *testing.T) { 135 enginetest.TestQueryErrors(t, newDoltHarness(t).withTransactionsEnabled(true)) 136 }) 137 } 138 139 func TestInfoSchema(t *testing.T) { 140 t.Run("no transactions", func(t *testing.T) { 141 enginetest.TestInfoSchema(t, newDoltHarness(t)) 142 }) 143 t.Run("with transactions", func(t *testing.T) { 144 enginetest.TestInfoSchema(t, newDoltHarness(t).withTransactionsEnabled(true)) 145 }) 146 } 147 148 func TestColumnAliases(t *testing.T) { 149 t.Run("no transactions", func(t *testing.T) { 150 enginetest.TestColumnAliases(t, newDoltHarness(t)) 151 }) 152 t.Run("with transactions", func(t *testing.T) { 153 enginetest.TestColumnAliases(t, newDoltHarness(t).withTransactionsEnabled(true)) 154 }) 155 } 156 157 func TestOrderByGroupBy(t *testing.T) { 158 t.Run("no transactions", func(t *testing.T) { 159 enginetest.TestOrderByGroupBy(t, newDoltHarness(t)) 160 }) 161 t.Run("with transactions", func(t *testing.T) { 162 enginetest.TestOrderByGroupBy(t, newDoltHarness(t).withTransactionsEnabled(true)) 163 }) 164 } 165 166 func TestAmbiguousColumnResolution(t *testing.T) { 167 t.Run("no transactions", func(t *testing.T) { 168 enginetest.TestAmbiguousColumnResolution(t, newDoltHarness(t)) 169 }) 170 t.Run("with transactions", func(t *testing.T) { 171 enginetest.TestAmbiguousColumnResolution(t, newDoltHarness(t).withTransactionsEnabled(true)) 172 }) 173 } 174 175 func TestInsertInto(t *testing.T) { 176 t.Run("no transactions", func(t *testing.T) { 177 enginetest.TestInsertInto(t, newDoltHarness(t)) 178 }) 179 t.Run("with transactions", func(t *testing.T) { 180 enginetest.TestInsertInto(t, newDoltHarness(t).withTransactionsEnabled(true)) 181 }) 182 } 183 184 func TestInsertIgnoreInto(t *testing.T) { 185 t.Run("no transactions", func(t *testing.T) { 186 enginetest.TestInsertIgnoreInto(t, newDoltHarness(t)) 187 }) 188 t.Run("with transactions", func(t *testing.T) { 189 enginetest.TestInsertIgnoreInto(t, newDoltHarness(t).withTransactionsEnabled(true)) 190 }) 191 } 192 193 func TestInsertIntoErrors(t *testing.T) { 194 t.Run("no transactions", func(t *testing.T) { 195 enginetest.TestInsertIntoErrors(t, newDoltHarness(t)) 196 }) 197 t.Run("with transactions", func(t *testing.T) { 198 enginetest.TestInsertIntoErrors(t, newDoltHarness(t).withTransactionsEnabled(true)) 199 }) 200 } 201 202 func TestReplaceInto(t *testing.T) { 203 t.Skipf("Skipping, replace returns the wrong number of rows in some cases") 204 enginetest.TestReplaceInto(t, newDoltHarness(t)) 205 } 206 207 func TestReplaceIntoErrors(t *testing.T) { 208 t.Run("no transactions", func(t *testing.T) { 209 enginetest.TestReplaceIntoErrors(t, newDoltHarness(t)) 210 }) 211 t.Run("with transactions", func(t *testing.T) { 212 enginetest.TestReplaceIntoErrors(t, newDoltHarness(t).withTransactionsEnabled(true)) 213 }) 214 } 215 216 func TestUpdate(t *testing.T) { 217 t.Run("no transactions", func(t *testing.T) { 218 enginetest.TestUpdate(t, newDoltHarness(t)) 219 }) 220 t.Run("with transactions", func(t *testing.T) { 221 enginetest.TestUpdate(t, newDoltHarness(t).withTransactionsEnabled(true)) 222 }) 223 } 224 225 func TestUpdateErrors(t *testing.T) { 226 t.Run("no transactions", func(t *testing.T) { 227 enginetest.TestUpdateErrors(t, newDoltHarness(t)) 228 }) 229 t.Run("with transactions", func(t *testing.T) { 230 enginetest.TestUpdateErrors(t, newDoltHarness(t).withTransactionsEnabled(true)) 231 }) 232 } 233 234 func TestDeleteFrom(t *testing.T) { 235 t.Run("no transactions", func(t *testing.T) { 236 enginetest.TestDelete(t, newDoltHarness(t)) 237 }) 238 t.Run("with transactions", func(t *testing.T) { 239 enginetest.TestDelete(t, newDoltHarness(t).withTransactionsEnabled(true)) 240 }) 241 } 242 243 func TestDeleteFromErrors(t *testing.T) { 244 t.Run("no transactions", func(t *testing.T) { 245 enginetest.TestDeleteErrors(t, newDoltHarness(t)) 246 }) 247 t.Run("with transactions", func(t *testing.T) { 248 enginetest.TestDeleteErrors(t, newDoltHarness(t).withTransactionsEnabled(true)) 249 }) 250 } 251 252 func TestTruncate(t *testing.T) { 253 t.Run("no transactions", func(t *testing.T) { 254 enginetest.TestTruncate(t, newDoltHarness(t)) 255 }) 256 t.Run("with transactions", func(t *testing.T) { 257 enginetest.TestTruncate(t, newDoltHarness(t).withTransactionsEnabled(true)) 258 }) 259 } 260 261 func TestScripts(t *testing.T) { 262 skipped := []string{ 263 "create index r_c0 on r (c0);", 264 } 265 t.Run("no transactions", func(t *testing.T) { 266 enginetest.TestScripts(t, newDoltHarness(t).WithSkippedQueries(skipped)) 267 }) 268 t.Run("with transactions", func(t *testing.T) { 269 enginetest.TestScripts(t, newDoltHarness(t).withTransactionsEnabled(true).WithSkippedQueries(skipped)) 270 }) 271 } 272 273 func TestCreateTable(t *testing.T) { 274 t.Run("no transactions", func(t *testing.T) { 275 enginetest.TestCreateTable(t, newDoltHarness(t)) 276 }) 277 t.Run("with transactions", func(t *testing.T) { 278 enginetest.TestCreateTable(t, newDoltHarness(t).withTransactionsEnabled(true)) 279 }) 280 } 281 282 func TestDropTable(t *testing.T) { 283 t.Run("no transactions", func(t *testing.T) { 284 enginetest.TestDropTable(t, newDoltHarness(t)) 285 }) 286 t.Run("with transactions", func(t *testing.T) { 287 enginetest.TestDropTable(t, newDoltHarness(t).withTransactionsEnabled(true)) 288 }) 289 } 290 291 func TestRenameTable(t *testing.T) { 292 t.Run("no transactions", func(t *testing.T) { 293 enginetest.TestRenameTable(t, newDoltHarness(t)) 294 }) 295 t.Run("with transactions", func(t *testing.T) { 296 enginetest.TestRenameTable(t, newDoltHarness(t).withTransactionsEnabled(true)) 297 }) 298 } 299 300 func TestRenameColumn(t *testing.T) { 301 t.Run("no transactions", func(t *testing.T) { 302 enginetest.TestRenameColumn(t, newDoltHarness(t)) 303 }) 304 t.Run("with transactions", func(t *testing.T) { 305 enginetest.TestRenameColumn(t, newDoltHarness(t).withTransactionsEnabled(true)) 306 }) 307 } 308 309 func TestAddColumn(t *testing.T) { 310 t.Run("no transactions", func(t *testing.T) { 311 enginetest.TestAddColumn(t, newDoltHarness(t)) 312 }) 313 t.Run("with transactions", func(t *testing.T) { 314 enginetest.TestAddColumn(t, newDoltHarness(t).withTransactionsEnabled(true)) 315 }) 316 } 317 318 func TestModifyColumn(t *testing.T) { 319 t.Run("no transactions", func(t *testing.T) { 320 enginetest.TestModifyColumn(t, newDoltHarness(t)) 321 }) 322 t.Run("with transactions", func(t *testing.T) { 323 enginetest.TestModifyColumn(t, newDoltHarness(t).withTransactionsEnabled(true)) 324 }) 325 } 326 327 func TestDropColumn(t *testing.T) { 328 t.Run("no transactions", func(t *testing.T) { 329 enginetest.TestDropColumn(t, newDoltHarness(t)) 330 }) 331 t.Run("with transactions", func(t *testing.T) { 332 enginetest.TestDropColumn(t, newDoltHarness(t).withTransactionsEnabled(true)) 333 }) 334 } 335 336 func TestCreateForeignKeys(t *testing.T) { 337 t.Run("no transactions", func(t *testing.T) { 338 enginetest.TestCreateForeignKeys(t, newDoltHarness(t)) 339 }) 340 t.Run("with transactions", func(t *testing.T) { 341 enginetest.TestCreateForeignKeys(t, newDoltHarness(t).withTransactionsEnabled(true)) 342 }) 343 } 344 345 func TestDropForeignKeys(t *testing.T) { 346 t.Run("no transactions", func(t *testing.T) { 347 enginetest.TestDropForeignKeys(t, newDoltHarness(t)) 348 }) 349 t.Run("with transactions", func(t *testing.T) { 350 enginetest.TestDropForeignKeys(t, newDoltHarness(t).withTransactionsEnabled(true)) 351 }) 352 } 353 354 func TestCreateCheckConstraints(t *testing.T) { 355 t.Run("no transactions", func(t *testing.T) { 356 enginetest.TestCreateCheckConstraints(t, newDoltHarness(t)) 357 }) 358 t.Run("with transactions", func(t *testing.T) { 359 enginetest.TestCreateCheckConstraints(t, newDoltHarness(t).withTransactionsEnabled(true)) 360 }) 361 } 362 363 func TestChecksOnInsert(t *testing.T) { 364 t.Run("no transactions", func(t *testing.T) { 365 enginetest.TestChecksOnInsert(t, newDoltHarness(t)) 366 }) 367 t.Run("with transactions", func(t *testing.T) { 368 enginetest.TestChecksOnInsert(t, newDoltHarness(t).withTransactionsEnabled(true)) 369 }) 370 } 371 372 func TestChecksOnUpdate(t *testing.T) { 373 t.Run("no transactions", func(t *testing.T) { 374 enginetest.TestChecksOnUpdate(t, newDoltHarness(t)) 375 }) 376 t.Run("with transactions", func(t *testing.T) { 377 enginetest.TestChecksOnUpdate(t, newDoltHarness(t).withTransactionsEnabled(true)) 378 }) 379 } 380 381 func TestDisallowedCheckConstraints(t *testing.T) { 382 t.Run("no transactions", func(t *testing.T) { 383 enginetest.TestDisallowedCheckConstraints(t, newDoltHarness(t)) 384 }) 385 t.Run("with transactions", func(t *testing.T) { 386 enginetest.TestDisallowedCheckConstraints(t, newDoltHarness(t).withTransactionsEnabled(true)) 387 }) 388 } 389 390 func TestDropCheckConstraints(t *testing.T) { 391 t.Run("no transactions", func(t *testing.T) { 392 enginetest.TestDropCheckConstraints(t, newDoltHarness(t)) 393 }) 394 t.Run("with transactions", func(t *testing.T) { 395 enginetest.TestDropCheckConstraints(t, newDoltHarness(t).withTransactionsEnabled(true)) 396 }) 397 } 398 399 func TestExplode(t *testing.T) { 400 t.Skipf("Unsupported types") 401 enginetest.TestExplode(t, newDoltHarness(t)) 402 } 403 404 func TestReadOnly(t *testing.T) { 405 t.Run("no transactions", func(t *testing.T) { 406 enginetest.TestReadOnly(t, newDoltHarness(t)) 407 }) 408 t.Run("with transactions", func(t *testing.T) { 409 enginetest.TestReadOnly(t, newDoltHarness(t).withTransactionsEnabled(true)) 410 }) 411 } 412 413 func TestViews(t *testing.T) { 414 t.Run("no transactions", func(t *testing.T) { 415 enginetest.TestViews(t, newDoltHarness(t)) 416 }) 417 t.Run("with transactions", func(t *testing.T) { 418 enginetest.TestViews(t, newDoltHarness(t).withTransactionsEnabled(true)) 419 }) 420 } 421 422 func TestVersionedViews(t *testing.T) { 423 t.Run("no transactions", func(t *testing.T) { 424 enginetest.TestVersionedViews(t, newDoltHarness(t)) 425 }) 426 t.Run("with transactions", func(t *testing.T) { 427 enginetest.TestVersionedViews(t, newDoltHarness(t).withTransactionsEnabled(true)) 428 }) 429 } 430 431 func TestNaturalJoin(t *testing.T) { 432 t.Run("no transactions", func(t *testing.T) { 433 enginetest.TestNaturalJoin(t, newDoltHarness(t)) 434 }) 435 t.Run("with transactions", func(t *testing.T) { 436 enginetest.TestNaturalJoin(t, newDoltHarness(t).withTransactionsEnabled(true)) 437 }) 438 } 439 440 func TestNaturalJoinEqual(t *testing.T) { 441 t.Run("no transactions", func(t *testing.T) { 442 enginetest.TestNaturalJoinEqual(t, newDoltHarness(t)) 443 }) 444 t.Run("with transactions", func(t *testing.T) { 445 enginetest.TestNaturalJoinEqual(t, newDoltHarness(t).withTransactionsEnabled(true)) 446 }) 447 } 448 449 func TestNaturalJoinDisjoint(t *testing.T) { 450 t.Run("no transactions", func(t *testing.T) { 451 enginetest.TestNaturalJoinEqual(t, newDoltHarness(t)) 452 }) 453 t.Run("with transactions", func(t *testing.T) { 454 enginetest.TestNaturalJoinEqual(t, newDoltHarness(t).withTransactionsEnabled(true)) 455 }) 456 } 457 458 func TestInnerNestedInNaturalJoins(t *testing.T) { 459 t.Run("no transactions", func(t *testing.T) { 460 enginetest.TestInnerNestedInNaturalJoins(t, newDoltHarness(t)) 461 }) 462 t.Run("with transactions", func(t *testing.T) { 463 enginetest.TestInnerNestedInNaturalJoins(t, newDoltHarness(t).withTransactionsEnabled(true)) 464 }) 465 } 466 467 func TestColumnDefaults(t *testing.T) { 468 t.Run("no transactions", func(t *testing.T) { 469 enginetest.TestColumnDefaults(t, newDoltHarness(t)) 470 }) 471 t.Run("with transactions", func(t *testing.T) { 472 enginetest.TestColumnDefaults(t, newDoltHarness(t).withTransactionsEnabled(true)) 473 }) 474 } 475 476 func TestVariables(t *testing.T) { 477 // Can't run these tests more than once because they set and make assertions about global vars, which obviously 478 // persist outside sessions. 479 enginetest.TestVariables(t, newDoltHarness(t)) 480 } 481 482 func TestVariableErrors(t *testing.T) { 483 t.Run("no transactions", func(t *testing.T) { 484 enginetest.TestVariableErrors(t, newDoltHarness(t)) 485 }) 486 t.Run("with transactions", func(t *testing.T) { 487 enginetest.TestVariableErrors(t, newDoltHarness(t).withTransactionsEnabled(true)) 488 }) 489 } 490 491 func TestJsonScripts(t *testing.T) { 492 t.Run("no transactions", func(t *testing.T) { 493 enginetest.TestJsonScripts(t, newDoltHarness(t)) 494 }) 495 t.Run("with transactions", func(t *testing.T) { 496 enginetest.TestJsonScripts(t, newDoltHarness(t).withTransactionsEnabled(true)) 497 }) 498 } 499 500 func TestTriggers(t *testing.T) { 501 t.Run("no transactions", func(t *testing.T) { 502 enginetest.TestTriggers(t, newDoltHarness(t)) 503 }) 504 t.Run("with transactions", func(t *testing.T) { 505 enginetest.TestTriggers(t, newDoltHarness(t).withTransactionsEnabled(true)) 506 }) 507 } 508 509 func TestStoredProcedures(t *testing.T) { 510 tests := make([]enginetest.ScriptTest, 0, len(enginetest.ProcedureLogicTests)) 511 for _, test := range enginetest.ProcedureLogicTests { 512 //TODO: fix REPLACE always returning a successful deletion 513 if test.Name != "Parameters resolve inside of REPLACE" { 514 tests = append(tests, test) 515 } 516 } 517 enginetest.ProcedureLogicTests = tests 518 519 t.Run("no transactions", func(t *testing.T) { 520 enginetest.TestStoredProcedures(t, newDoltHarness(t)) 521 }) 522 t.Run("with transactions", func(t *testing.T) { 523 enginetest.TestStoredProcedures(t, newDoltHarness(t).withTransactionsEnabled(true)) 524 }) 525 } 526 527 func TestTransactions(t *testing.T) { 528 enginetest.TestTransactionScripts(t, newDoltHarness(t).withTransactionsEnabled(true)) 529 for _, script := range DoltTransactionTests { 530 enginetest.TestTransactionScript(t, newDoltHarness(t).withTransactionsEnabled(true), script) 531 } 532 } 533 534 func TestSystemTableQueries(t *testing.T) { 535 enginetest.RunQueryTests(t, newDoltHarness(t), BrokenSystemTableQueries) 536 }