Skip to content

Commit

Permalink
opt/opbench: add more cost tests
Browse files Browse the repository at this point in the history
This commit introduces more costing tests for some scans and sorts.

Release note: None
  • Loading branch information
Justin Jaffray committed Apr 1, 2019
1 parent 668162c commit c2b9972
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 0 deletions.
146 changes: 146 additions & 0 deletions pkg/sql/opt/opbench/opbench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ var Benches = []*opbench.Spec{
HashJoinSpec,
MergeJoinSpec,
LookupJoinSpec,
SortLineitemSpec,
ScanOrdersSpec,
ScanLineitemSpec,
}

// HashJoinSpec does a hash join between supplier and lineitem.
Expand Down Expand Up @@ -452,3 +455,146 @@ var LookupJoinSpec = &opbench.Spec{
panic(fmt.Sprintf("can't handle %q", paramName))
},
}

func makeScanSpec(
name string,
tableName string,
rowCounts []float64,
colCounts []float64,
colNames []string,
) *opbench.Spec {
return &opbench.Spec{
Name: name,
Plan: fmt.Sprintf(`
(Root
(Scan
[
(Table "%s")
(Cols "$cols")
(HardLimit $rows)
]
)
(Presentation "$cols")
(NoOrdering)
)`, tableName),

Inputs: []opbench.Options{
{Field: "rows", Values: rowCounts},
{Field: "num_cols", Values: colCounts},
},

GetParam: func(paramName string, config opbench.Configuration) string {
switch paramName {
case "rows":
return fmt.Sprintf("%d", int(config["rows"]))
case "cols":
c := int(config["num_cols"])
var result bytes.Buffer
for i := 0; i < c; i++ {
if i > 0 {
result.WriteByte(',')
}
result.WriteString(colNames[i])
}
return result.String()
}
panic(fmt.Sprintf("can't handle %q", paramName))
},
}
}

// ScanLineitemSpec scans the lineitem table.
var ScanLineitemSpec = makeScanSpec(
"scan-lineitem",
"lineitem",
[]float64{1000000, 2000000, 3000000, 4000000, 5000000, 6000000},
[]float64{1, 2, 3, 4, 16},
[]string{
"l_orderkey", "l_partkey", "l_suppkey",
"l_linenumber", "l_quantity", "l_extendedprice",
"l_discount", "l_tax", "l_returnflag",
"l_linestatus", "l_shipdate", "l_commitdate",
"l_receiptdate", "l_shipinstruct", "l_shipmode",
"l_comment",
},
)

// ScanOrdersSpec scans the orders table.
var ScanOrdersSpec = makeScanSpec(
"scan-orders",
"orders",
[]float64{250000, 500000, 750000, 1000000, 1250000, 1500000},
[]float64{1, 3, 6, 9},
[]string{
"o_orderkey", "o_custkey", "o_orderstatus",
"o_totalprice", "o_orderdate", "o_orderpriority",
"o_clerk", "o_shippriority", "o_comment",
},
)

func makeSortSpec(
name string,
tableName string,
rowCounts []float64,
colCounts []float64,
colNames []string,
ordering string,
) *opbench.Spec {
return &opbench.Spec{
Name: name,
Plan: fmt.Sprintf(`
(Root
(Sort
(Scan
[
(Table "%s")
(Cols "$cols")
(HardLimit $rows)
]
)
)
(Presentation "$cols")
(OrderingChoice "%s")
)`, tableName, ordering),

Inputs: []opbench.Options{
{Field: "rows", Values: rowCounts},
{Field: "num_cols", Values: colCounts},
},

GetParam: func(paramName string, config opbench.Configuration) string {
switch paramName {
case "rows":
return fmt.Sprintf("%d", int(config["rows"]))
case "cols":
c := int(config["num_cols"])
var result bytes.Buffer
for i := 0; i < c; i++ {
if i > 0 {
result.WriteByte(',')
}
result.WriteString(colNames[i])
}
return result.String()
}
panic(fmt.Sprintf("can't handle %q", paramName))
},
}
}

// SortLineitemSpec scans the lineitem table.
var SortLineitemSpec = makeSortSpec(
"sort-lineitem",
"lineitem",
[]float64{1000000, 2000000, 3000000, 4000000, 5000000, 6000000},
[]float64{1, 2, 3},
[]string{
"l_orderkey", "l_partkey", "l_suppkey",
"l_linenumber", "l_quantity", "l_extendedprice",
"l_discount", "l_tax", "l_returnflag",
"l_linestatus", "l_shipdate", "l_commitdate",
"l_receiptdate", "l_shipinstruct", "l_shipmode",
"l_comment",
},
"+l_orderkey",
)
31 changes: 31 additions & 0 deletions pkg/sql/opt/opbench/testdata/scan-lineitem.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
rows,num_cols,estimated,actual
1000000,1,1170000.010000,0.834084
2000000,1,2340000.010000,1.489845
3000000,1,3510000.010000,2.211772
4000000,1,4680000.010000,2.787555
5000000,1,5850000.010000,3.727968
6000000,1,7020000.010000,4.538592
1000000,2,1180000.010000,0.856709
2000000,2,2360000.010000,1.689832
3000000,2,3540000.010000,2.624644
4000000,2,4720000.010000,3.354893
5000000,2,5900000.010000,4.149957
6000000,2,7080000.010000,5.126522
1000000,3,1190000.010000,0.948950
2000000,3,2380000.010000,1.844214
3000000,3,3570000.010000,2.819678
4000000,3,4760000.010000,3.689639
5000000,3,5950000.010000,4.598679
6000000,3,7140000.010000,5.589131
1000000,4,1200000.010000,0.963368
2000000,4,2400000.010000,1.907634
3000000,4,3600000.010000,2.819860
4000000,4,4800000.010000,3.835917
5000000,4,6000000.010000,4.603531
6000000,4,7200000.010000,5.676630
1000000,16,1320000.010000,1.951303
2000000,16,2640000.010000,3.845009
3000000,16,3960000.010000,5.823685
4000000,16,5280000.010000,7.786907
5000000,16,6600000.010000,9.746737
6000000,16,7920000.010000,11.603873
25 changes: 25 additions & 0 deletions pkg/sql/opt/opbench/testdata/scan-orders.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
rows,num_cols,estimated,actual
250000,1,275000.010000,0.234685
500000,1,550000.010000,0.355673
750000,1,825000.010000,0.536125
1000000,1,1100000.010000,0.735832
1250000,1,1375000.010000,0.909200
1500000,1,1650000.010000,1.036382
250000,3,280000.010000,0.226567
500000,3,560000.010000,0.441384
750000,3,840000.010000,0.611747
1000000,3,1120000.010000,0.881042
1250000,3,1400000.010000,1.092393
1500000,3,1680000.010000,1.314116
250000,6,287500.010000,0.292452
500000,6,575000.010000,0.496511
750000,6,862500.010000,0.817809
1000000,6,1150000.010000,1.162477
1250000,6,1437500.010000,1.451609
1500000,6,1725000.010000,1.760463
250000,9,295000.010000,0.360331
500000,9,590000.010000,0.626732
750000,9,885000.010000,0.992292
1000000,9,1180000.010000,1.368585
1250000,9,1475000.010000,1.727139
1500000,9,1770000.010000,2.056275
19 changes: 19 additions & 0 deletions pkg/sql/opt/opbench/testdata/sort-lineitem.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
rows,num_cols,estimated,actual
1000000,1,1588631.391386,1.467528
2000000,1,3217262.762773,3.007519
3000000,1,4860991.884203,5.827569
4000000,1,6514525.505546,7.106306
5000000,1,8175349.686421,8.982024
6000000,1,9841983.748405,10.749726
1000000,2,1598631.391386,1.665857
2000000,2,3237262.762773,4.036806
3000000,2,4890991.884203,6.109568
4000000,2,6554525.505546,8.072787
5000000,2,8225349.686421,9.743525
6000000,2,9901983.748405,12.756862
1000000,3,1608631.391386,2.786447
2000000,3,3257262.762773,4.812669
3000000,3,4920991.884203,7.417335
4000000,3,6594525.505546,11.088666
5000000,3,8275349.686421,12.703216
6000000,3,9961983.748405,14.615791

0 comments on commit c2b9972

Please sign in to comment.