-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
select
130 lines (123 loc) · 3.25 KB
/
select
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
exec-ddl
CREATE TABLE a
(
k INT PRIMARY KEY,
u INT,
v INT,
INDEX u(u),
UNIQUE INDEX v(v)
)
----
TABLE a
├── k int not null
├── u int
├── v int
├── INDEX primary
│ └── k int not null
├── INDEX u
│ ├── u int
│ └── k int not null
└── INDEX v
├── v int
└── k int not null (storing)
# --------------------------------------------------
# ConstrainScan
# --------------------------------------------------
opt
SELECT k FROM a WHERE k = 1
----
scan a,constrained
├── columns: k:1(int!null)
└── constraint: /1: [/1 - /1]
memo
SELECT k FROM a WHERE k = 1
----
[9: "p:k:1"]
memo
├── 10: (true)
├── 9: (select 8 5) (scan a,constrained)
│ └── "p:k:1" [cost=100.00]
│ └── best: (scan a,constrained)
├── 8: (scan a) (scan a@u) (scan a@v)
│ └── "" [cost=1000.00]
│ └── best: (scan a)
├── 7: (projections 2)
├── 6: (select 1 5)
├── 5: (filters 4)
├── 4: (eq 2 3)
├── 3: (const 1)
├── 2: (variable a.k)
└── 1: (scan a)
opt
SELECT k FROM a WHERE v > 1
----
project
├── columns: k:1(int!null)
├── scan a@v,constrained
│ ├── columns: a.k:1(int!null) a.v:3(int)
│ └── constraint: /3: [/2 - ]
└── projections [outer=(1)]
└── variable: a.k [type=int, outer=(1)]
memo
SELECT k FROM a WHERE v > 1
----
[11: "p:k:1"]
memo
├── 12: (true)
├── 11: (project 10 8)
│ └── "p:k:1" [cost=100.00]
│ └── best: (project 10 8)
├── 10: (select 9 5) (scan a@v,constrained)
│ └── "" [cost=100.00]
│ └── best: (scan a@v,constrained)
├── 9: (scan a) (scan a@v)
│ └── "" [cost=1000.00]
│ └── best: (scan a)
├── 8: (projections 7)
├── 7: (variable a.k)
├── 6: (select 1 5)
├── 5: (filters 4)
├── 4: (gt 2 3)
├── 3: (const 1)
├── 2: (variable a.v)
└── 1: (scan a)
opt
SELECT k FROM a WHERE u = 1 AND k = 5
----
project
├── columns: k:1(int!null)
├── scan a@u,constrained
│ ├── columns: a.k:1(int!null) a.u:2(int)
│ └── constraint: /2/1: [/1/5 - /1/5]
└── projections [outer=(1)]
└── variable: a.k [type=int, outer=(1)]
memo
SELECT k FROM a WHERE u = 1 AND k = 5
----
[14: "p:k:1"]
memo
├── 17: (scan a,constrained)
│ └── "" [cost=100.00]
│ └── best: (scan a,constrained)
├── 16: (filters 4)
├── 15: (true)
├── 14: (project 13 11)
│ └── "p:k:1" [cost=100.00]
│ └── best: (project 13 11)
├── 13: (select 12 9) (select 17 16) (scan a@u,constrained)
│ └── "" [cost=100.00]
│ └── best: (scan a@u,constrained)
├── 12: (scan a) (scan a@u)
│ └── "" [cost=1000.00]
│ └── best: (scan a)
├── 11: (projections 5)
├── 10: (select 1 9)
├── 9: (filters 4 7)
├── 8: (and 4 7)
├── 7: (eq 5 6)
├── 6: (const 5)
├── 5: (variable a.k)
├── 4: (eq 2 3)
├── 3: (const 1)
├── 2: (variable a.u)
└── 1: (scan a)