Skip to content

Commit

Permalink
Add query plans for index/join sysbench queries (#2133)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-hoffman authored Nov 7, 2023
1 parent 99ca3db commit cf4306a
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 25 deletions.
4 changes: 4 additions & 0 deletions enginetest/plangen/cmd/plangen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ func specSetup(name string) [][]setup.SetupScript {
return setup.TpccPlanSetup
case "GeneratedColumnPlanTests":
return setup.GeneratedColumnSetup
case "SysbenchPlanTests":
return setup.SysbenchSetup
default:
exit(fmt.Errorf("setup not found for plan suite: %s", name))
return nil
Expand All @@ -240,6 +242,8 @@ func specQueries(name string) []queries.QueryPlanTest {
return queries.IntegrationPlanTests
case "GeneratedColumnPlanTests":
return queries.GeneratedColumnPlanTests
case "SysbenchPlanTests":
return queries.SysbenchPlanTests
default:
exit(fmt.Errorf("queries not found for plan suite: %s", name))
return nil
Expand Down
4 changes: 3 additions & 1 deletion enginetest/plangen/testdata/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ plans:
- name: ImdbPlanTests
path: enginetest/queries/imdb_plans.go
- name: GeneratedColumnPlanTests
path: enginetest/queries/generated_column_plans.go
path: enginetest/queries/generated_column_plans.go
- name: SysbenchPlanTests
path: enginetest/queries/sysbench_plans.go
22 changes: 22 additions & 0 deletions enginetest/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ type QueryTest struct {
SkipPrepared bool
}

type QueryPlanTest struct {
Query string
ExpectedPlan string
Skip bool
}

// QueryPlanTODOs are queries where the query planner produces a correct (results) but suboptimal plan.
var QueryPlanTODOs = []QueryPlanTest{
{
// TODO: this should use an index. Extra join condition should get moved out of the join clause into a filter
Query: `SELECT pk,i,f FROM one_pk RIGHT JOIN niltable ON pk=i and pk > 0 ORDER BY 2,3`,
ExpectedPlan: "Sort(niltable.i ASC, niltable.f ASC)\n" +
" └─ Project(one_pk.pk, niltable.i, niltable.f)\n" +
" └─ RightJoin((one_pk.pk = niltable.i) AND (one_pk.pk > 0))\n" +
" ├─ Projected table access on [pk]\n" +
" │ └─ Table(one_pk)\n" +
" └─ Projected table access on [i f]\n" +
" └─ Table(niltable)\n" +
"",
},
}

var SpatialQueryTests = []QueryTest{
{
Query: `SHOW CREATE TABLE point_table`,
Expand Down
22 changes: 0 additions & 22 deletions enginetest/queries/query_plans.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 106 additions & 0 deletions enginetest/queries/sysbench_plans.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions enginetest/scriptgen/cmd/scriptgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"github.com/dolthub/go-mysql-server/enginetest/scriptgen/setup"
)

//go:generate go run ./main.go -out ../../setup/setup_data.sg.go -pkg setup setup ../../setup/scripts

var (
errInvalidArgCount = errors.New("invalid number of arguments")
errUnrecognizedCommand = errors.New("unrecognized command")
Expand Down
1 change: 1 addition & 0 deletions enginetest/scriptgen/setup/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
GraphSetup = [][]SetupScript{MydbData, Graph_tablesData}
ReservedSetup = [][]SetupScript{MydbData, Reserved_keywordsData}
GeneratedColumnSetup = [][]SetupScript{MydbData, Generated_column_tablesData}
SysbenchSetup = [][]SetupScript{MydbData, SysbenchData}
Mytable = [][]SetupScript{MydbData, MytableData}
ChecksSetup = [][]SetupScript{MydbData, Check_constraintData}
NullsSetup = [][]SetupScript{MydbData, Null_rangesData}
Expand Down
2 changes: 0 additions & 2 deletions enginetest/scriptgen/setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
ast "github.com/dolthub/vitess/go/vt/sqlparser"
)

//go:generate go run ../cmd/scriptgen/main.go -out setup_data.sg.go -pkg setup setup scripts

type setupSource interface {
Next() (bool, error)
Close() error
Expand Down
49 changes: 49 additions & 0 deletions enginetest/scriptgen/setup/scripts/sysbench
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
exec
CREATE TABLE `sbtest1` (
`id` int NOT NULL,
`tiny_int_col` tinyint NOT NULL,
`unsigned_tiny_int_col` tinyint unsigned NOT NULL,
`small_int_col` smallint NOT NULL,
`unsigned_small_int_col` smallint unsigned NOT NULL,
`medium_int_col` mediumint NOT NULL,
`unsigned_medium_int_col` mediumint unsigned NOT NULL,
`int_col` int NOT NULL,
`unsigned_int_col` int unsigned NOT NULL,
`big_int_col` bigint NOT NULL,
`unsigned_big_int_col` bigint unsigned NOT NULL,
`decimal_col` decimal(10,0) NOT NULL,
`float_col` float NOT NULL,
`double_col` double NOT NULL,
`bit_col` bit(1) NOT NULL,
`char_col` char(1) NOT NULL,
`var_char_col` varchar(64) NOT NULL,
`enum_col` enum('val0','val1','val2') NOT NULL,
`set_col` set('val0','val1','val2') NOT NULL,
`date_col` date NOT NULL,
`time_col` time(6) NOT NULL,
`datetime_col` datetime NOT NULL,
`timestamp_col` timestamp NOT NULL,
`year_col` year NOT NULL,
PRIMARY KEY (`id`),
KEY `big_int_col` (`big_int_col`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin
---

exec
CREATE TABLE `sbtest2` (
`id` int NOT NULL,
`int_col` int NOT NULL,
`unsigned_int_col` int unsigned NOT NULL,
`char_col` char(1) NOT NULL,
`var_char_col` varchar(64) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin
----

exec
analyze table sbtest1 update histogram on id using data '{\"row_count\": 10000}';
----

exec
analyze table sbtest2 update histogram on id using data '{\"row_count\": 10000}';
----
7 changes: 7 additions & 0 deletions enginetest/scriptgen/setup/setup_data.sg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cf4306a

Please sign in to comment.