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

     1  // Copyright 2021 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  )
    20  
    21  // DoltDiffPlanTests are tests that check our query plans for various operations on the dolt diff system tables
    22  var DoltDiffPlanTests = []queries.QueryPlanTest{
    23  	{
    24  		Query: `select * from dolt_diff_one_pk where to_pk=1`,
    25  		ExpectedPlan: "Filter\n" +
    26  			" ├─ (dolt_diff_one_pk.to_pk = 1)\n" +
    27  			" └─ IndexedTableAccess(dolt_diff_one_pk)\n" +
    28  			"     ├─ index: [dolt_diff_one_pk.to_pk]\n" +
    29  			"     └─ filters: [{[1, 1]}]\n" +
    30  			"",
    31  	},
    32  	{
    33  		Query: `select * from dolt_diff_one_pk where to_pk>=10 and to_pk<=100`,
    34  		ExpectedPlan: "Filter\n" +
    35  			" ├─ ((dolt_diff_one_pk.to_pk >= 10) AND (dolt_diff_one_pk.to_pk <= 100))\n" +
    36  			" └─ IndexedTableAccess(dolt_diff_one_pk)\n" +
    37  			"     ├─ index: [dolt_diff_one_pk.to_pk]\n" +
    38  			"     └─ filters: [{[10, 100]}]\n" +
    39  			"",
    40  	},
    41  	{
    42  		Query: `select * from dolt_diff_two_pk where to_pk1=1`,
    43  		ExpectedPlan: "Filter\n" +
    44  			" ├─ (dolt_diff_two_pk.to_pk1 = 1)\n" +
    45  			" └─ IndexedTableAccess(dolt_diff_two_pk)\n" +
    46  			"     ├─ index: [dolt_diff_two_pk.to_pk1,dolt_diff_two_pk.to_pk2]\n" +
    47  			"     └─ filters: [{[1, 1], [NULL, ∞)}]\n" +
    48  			"",
    49  	},
    50  	{
    51  		Query: `select * from dolt_diff_two_pk where to_pk1=1 and to_pk2=2`,
    52  		ExpectedPlan: "Filter\n" +
    53  			" ├─ ((dolt_diff_two_pk.to_pk1 = 1) AND (dolt_diff_two_pk.to_pk2 = 2))\n" +
    54  			" └─ IndexedTableAccess(dolt_diff_two_pk)\n" +
    55  			"     ├─ index: [dolt_diff_two_pk.to_pk1,dolt_diff_two_pk.to_pk2]\n" +
    56  			"     └─ filters: [{[1, 1], [2, 2]}]\n" +
    57  			"",
    58  	},
    59  	{
    60  		Query: `select * from dolt_diff_two_pk where to_pk1 < 1 and to_pk2 > 10`,
    61  		ExpectedPlan: "Filter\n" +
    62  			" ├─ ((dolt_diff_two_pk.to_pk1 < 1) AND (dolt_diff_two_pk.to_pk2 > 10))\n" +
    63  			" └─ IndexedTableAccess(dolt_diff_two_pk)\n" +
    64  			"     ├─ index: [dolt_diff_two_pk.to_pk1,dolt_diff_two_pk.to_pk2]\n" +
    65  			"     └─ filters: [{(NULL, 1), (10, ∞)}]\n" +
    66  			"",
    67  	},
    68  }
    69  
    70  var DoltCommitPlanTests = []queries.QueryPlanTest{
    71  	{
    72  		Query: "select * from dolt_log order by commit_hash;",
    73  		ExpectedPlan: "Sort(dolt_log.commit_hash ASC)\n" +
    74  			" └─ Exchange\n" +
    75  			"     └─ Table\n" +
    76  			"         └─ name: dolt_log\n" +
    77  			"",
    78  	},
    79  	{
    80  		Query: "select * from dolt_diff order by commit_hash;",
    81  		ExpectedPlan: "Sort(dolt_diff.commit_hash ASC)\n" +
    82  			" └─ Exchange\n" +
    83  			"     └─ Table\n" +
    84  			"         └─ name: dolt_diff\n" +
    85  			"",
    86  	},
    87  	{
    88  		Query: "select * from dolt_commits order by commit_hash;",
    89  		ExpectedPlan: "Sort(dolt_commits.commit_hash ASC)\n" +
    90  			" └─ Exchange\n" +
    91  			"     └─ Table\n" +
    92  			"         └─ name: dolt_commits\n" +
    93  			"",
    94  	},
    95  	{
    96  		Query: "select * from dolt_commit_ancestors order by commit_hash;",
    97  		ExpectedPlan: "Sort(dolt_commit_ancestors.commit_hash ASC)\n" +
    98  			" └─ Exchange\n" +
    99  			"     └─ Table\n" +
   100  			"         └─ name: dolt_commit_ancestors\n" +
   101  			"",
   102  	},
   103  }