Skip to content

Commit

Permalink
workload/tpcc: add missing new_order -> order foreign key
Browse files Browse the repository at this point in the history
  • Loading branch information
nvanbenschoten committed May 20, 2019
1 parent 4b384ce commit 230dae9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 34 deletions.
44 changes: 23 additions & 21 deletions pkg/sql/opt/xform/testdata/external/tpcc
Original file line number Diff line number Diff line change
Expand Up @@ -641,17 +641,19 @@ CREATE TABLE new_order
no_o_id integer not null,
no_d_id integer not null,
no_w_id integer not null,
primary key (no_w_id, no_d_id, no_o_id DESC)
primary key (no_w_id, no_d_id, no_o_id),
foreign key (no_w_id, no_d_id, no_o_id) references "order" (o_w_id, o_d_id, o_id)
) interleave in parent "order" (no_w_id, no_d_id, no_o_id)
----
TABLE new_order
├── no_o_id int not null
├── no_d_id int not null
├── no_w_id int not null
└── INDEX primary
├── no_w_id int not null
├── no_d_id int not null
└── no_o_id int not null desc
├── INDEX primary
│ ├── no_w_id int not null
│ ├── no_d_id int not null
│ └── no_o_id int not null
└── FOREIGN KEY (no_w_id, no_d_id, no_o_id) REFERENCES t.public."order" (o_w_id, o_d_id, o_id)

exec-ddl
ALTER TABLE new_order INJECT STATISTICS '[
Expand Down Expand Up @@ -1321,16 +1323,16 @@ project
├── key: ()
├── fd: ()-->(1)
├── prune: (1)
└── scan new_order,rev
└── scan new_order
├── columns: no_o_id:1(int!null) no_d_id:2(int!null) no_w_id:3(int!null)
├── constraint: /3/2/-1: [/10/100 - /10/100]
├── limit: 1(rev)
├── constraint: /3/2/1: [/10/100 - /10/100]
├── limit: 1
├── stats: [rows=1]
├── cost: 1.07
├── key: ()
├── fd: ()-->(1-3)
├── prune: (1-3)
└── interesting orderings: (+3,+2,-1)
└── interesting orderings: (+3,+2,+1)

opt format=hide-qual
SELECT sum(ol_amount)
Expand Down Expand Up @@ -1542,7 +1544,7 @@ group-by
│ ├── key: (1-3)
│ ├── ordering: +3,+2
│ ├── prune: (1-3)
│ └── interesting orderings: (+3,+2,-1)
│ └── interesting orderings: (+3,+2,+1)
└── aggregations
└── max [type=int, outer=(1)]
└── variable: no_o_id [type=int]
Expand Down Expand Up @@ -1617,7 +1619,7 @@ scalar-group-by
│ │ │ ├── key: (1-3)
│ │ │ ├── ordering: +3,+2
│ │ │ ├── prune: (1-3)
│ │ │ └── interesting orderings: (+3,+2,-1)
│ │ │ └── interesting orderings: (+3,+2,+1)
│ │ └── aggregations
│ │ ├── max [type=int, outer=(1)]
│ │ │ └── variable: no_o_id [type=int]
Expand Down Expand Up @@ -1710,7 +1712,7 @@ except-all
│ ├── cost: 954000.02
│ ├── key: (1-3)
│ ├── prune: (1-3)
│ └── interesting orderings: (+3,+2,-1)
│ └── interesting orderings: (+3,+2,+1)
└── project
├── columns: o_id:4(int!null) o_d_id:5(int!null) o_w_id:6(int!null)
├── stats: [rows=240000]
Expand Down Expand Up @@ -1783,7 +1785,7 @@ except-all
├── cost: 954000.02
├── key: (9-11)
├── prune: (9-11)
└── interesting orderings: (+11,+10,-9)
└── interesting orderings: (+11,+10,+9)

opt format=hide-qual
(
Expand Down Expand Up @@ -2952,16 +2954,16 @@ project
├── key: ()
├── fd: ()-->(1)
├── prune: (1)
└── scan new_order,rev
└── scan new_order
├── columns: no_o_id:1(int!null) no_d_id:2(int!null) no_w_id:3(int!null)
├── constraint: /3/2/-1: [/10/100 - /10/100]
├── limit: 1(rev)
├── constraint: /3/2/1: [/10/100 - /10/100]
├── limit: 1
├── stats: [rows=1]
├── cost: 1.07
├── key: ()
├── fd: ()-->(1-3)
├── prune: (1-3)
└── interesting orderings: (+3,+2,-1)
└── interesting orderings: (+3,+2,+1)

opt format=hide-qual
SELECT sum(ol_amount)
Expand Down Expand Up @@ -3173,7 +3175,7 @@ group-by
│ ├── key: (1-3)
│ ├── ordering: +3,+2
│ ├── prune: (1-3)
│ └── interesting orderings: (+3,+2,-1)
│ └── interesting orderings: (+3,+2,+1)
└── aggregations
└── max [type=int, outer=(1)]
└── variable: no_o_id [type=int]
Expand Down Expand Up @@ -3248,7 +3250,7 @@ scalar-group-by
│ │ │ ├── key: (1-3)
│ │ │ ├── ordering: +3,+2
│ │ │ ├── prune: (1-3)
│ │ │ └── interesting orderings: (+3,+2,-1)
│ │ │ └── interesting orderings: (+3,+2,+1)
│ │ └── aggregations
│ │ ├── max [type=int, outer=(1)]
│ │ │ └── variable: no_o_id [type=int]
Expand Down Expand Up @@ -3341,7 +3343,7 @@ except-all
│ ├── cost: 12001.34
│ ├── key: (1-3)
│ ├── prune: (1-3)
│ └── interesting orderings: (+3,+2,-1)
│ └── interesting orderings: (+3,+2,+1)
└── project
├── columns: o_id:4(int!null) o_d_id:5(int!null) o_w_id:6(int!null)
├── stats: [rows=6560471]
Expand Down Expand Up @@ -3414,7 +3416,7 @@ except-all
├── cost: 12001.34
├── key: (9-11)
├── prune: (9-11)
└── interesting orderings: (+11,+10,-9)
└── interesting orderings: (+11,+10,+9)

opt format=hide-qual
(
Expand Down
28 changes: 15 additions & 13 deletions pkg/sql/opt/xform/testdata/external/tpcc-no-stats
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,19 @@ CREATE TABLE new_order
no_o_id integer not null,
no_d_id integer not null,
no_w_id integer not null,
primary key (no_w_id, no_d_id, no_o_id DESC)
primary key (no_w_id, no_d_id, no_o_id),
foreign key (no_w_id, no_d_id, no_o_id) references "order" (o_w_id, o_d_id, o_id)
) interleave in parent "order" (no_w_id, no_d_id, no_o_id)
----
TABLE new_order
├── no_o_id int not null
├── no_d_id int not null
├── no_w_id int not null
└── INDEX primary
├── no_w_id int not null
├── no_d_id int not null
└── no_o_id int not null desc
├── INDEX primary
│ ├── no_w_id int not null
│ ├── no_d_id int not null
│ └── no_o_id int not null
└── FOREIGN KEY (no_w_id, no_d_id, no_o_id) REFERENCES t.public."order" (o_w_id, o_d_id, o_id)

exec-ddl
CREATE TABLE item
Expand Down Expand Up @@ -625,16 +627,16 @@ project
├── key: ()
├── fd: ()-->(1)
├── prune: (1)
└── scan new_order,rev
└── scan new_order
├── columns: no_o_id:1(int!null) no_d_id:2(int!null) no_w_id:3(int!null)
├── constraint: /3/2/-1: [/10/100 - /10/100]
├── limit: 1(rev)
├── constraint: /3/2/1: [/10/100 - /10/100]
├── limit: 1
├── stats: [rows=0.1]
├── cost: 0.116
├── key: ()
├── fd: ()-->(1-3)
├── prune: (1-3)
└── interesting orderings: (+3,+2,-1)
└── interesting orderings: (+3,+2,+1)

opt format=hide-qual
SELECT sum(ol_amount)
Expand Down Expand Up @@ -837,7 +839,7 @@ group-by
│ ├── key: (1-3)
│ ├── ordering: +3,+2
│ ├── prune: (1-3)
│ └── interesting orderings: (+3,+2,-1)
│ └── interesting orderings: (+3,+2,+1)
└── aggregations
└── max [type=int, outer=(1)]
└── variable: no_o_id [type=int]
Expand Down Expand Up @@ -912,7 +914,7 @@ scalar-group-by
│ │ │ ├── key: (1-3)
│ │ │ ├── ordering: +3,+2
│ │ │ ├── prune: (1-3)
│ │ │ └── interesting orderings: (+3,+2,-1)
│ │ │ └── interesting orderings: (+3,+2,+1)
│ │ └── aggregations
│ │ ├── max [type=int, outer=(1)]
│ │ │ └── variable: no_o_id [type=int]
Expand Down Expand Up @@ -1000,7 +1002,7 @@ except-all
│ ├── cost: 1060.02
│ ├── key: (1-3)
│ ├── prune: (1-3)
│ └── interesting orderings: (+3,+2,-1)
│ └── interesting orderings: (+3,+2,+1)
└── project
├── columns: o_id:4(int!null) o_d_id:5(int!null) o_w_id:6(int!null)
├── stats: [rows=10]
Expand Down Expand Up @@ -1073,7 +1075,7 @@ except-all
├── cost: 1060.02
├── key: (9-11)
├── prune: (9-11)
└── interesting orderings: (+11,+10,-9)
└── interesting orderings: (+11,+10,+9)

opt format=hide-qual
(
Expand Down
1 change: 1 addition & 0 deletions pkg/workload/tpcc/tpcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func (w *tpcc) Hooks() workload.Hooks {
`alter table history add foreign key (h_c_w_id, h_c_d_id, h_c_id) references customer (c_w_id, c_d_id, c_id)`,
`alter table history add foreign key (h_w_id, h_d_id) references district (d_w_id, d_id)`,
`alter table "order" add foreign key (o_w_id, o_d_id, o_c_id) references customer (c_w_id, c_d_id, c_id)`,
`alter table new_order add foreign key (no_w_id, no_d_id, no_o_id) references "order" (o_w_id, o_d_id, o_id)`,
`alter table stock add foreign key (s_w_id) references warehouse (w_id)`,
`alter table stock add foreign key (s_i_id) references item (i_id)`,
`alter table order_line add foreign key (ol_w_id, ol_d_id, ol_o_id) references "order" (o_w_id, o_d_id, o_id)`,
Expand Down

0 comments on commit 230dae9

Please sign in to comment.