Skip to content

Commit 88cbf80

Browse files
authored
add test for HashedArrayOp (#1034)
1 parent b39490a commit 88cbf80

5 files changed

Lines changed: 487 additions & 1 deletion

File tree

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
--- Test for HashedArrayOp optimization
3+
---
4+
SET search_path = public;
5+
SET enable_seqscan = off;
6+
SET max_parallel_workers_per_gather = 0;
7+
SET pg_strom.explain_developer_mode = on;
8+
VACUUM ANALYZE lineorder;
9+
-- IN-list with 3 constants keeps ScalarArrayOpAny
10+
EXPLAIN (verbose, costs off)
11+
SELECT lo_orderkey
12+
FROM lineorder
13+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL');
14+
QUERY PLAN
15+
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
16+
Custom Scan (GpuScan) on public.lineorder
17+
Output: lo_orderkey
18+
GPU Projection: lineorder.lo_orderkey
19+
GPU Scan Quals: (lineorder.lo_shipmode = ANY ('{RAIL,SHIP,MAIL}'::bpchar[]))
20+
KVars-Slot: <slot=0, type='bpchar', expr='NULL::bpchar'>, <slot=1, type='bpchar', expr='lo_shipmode', kv_off=0x0000>, <slot=2, type='int8', expr='lo_orderkey', kv_off=0x3400>
21+
KVecs-Buffer: nbytes: 22528, ndims: 2, items=[kvec0=<0x0000-33ff, type='bpchar', expr='lo_shipmode'>, kvec1=<0x3400-57ff, type='int8', expr='lo_orderkey'>]
22+
LoadVars OpCode: {Packed items[0]={LoadVars(depth=0): kvars=[<slot=2, type='int8' resno=1(lo_orderkey)>, <slot=1, type='bpchar' resno=17(lo_shipmode)>]}}
23+
MoveVars OpCode: {Packed items[0]={MoveVars(depth=0): items=[<slot=2, offset=0x3400-57ff, type='int8', expr='lo_orderkey'>]}}}
24+
Scan Quals OpCode: {ScalarArrayOpAny: elem=<slot=0, type='bpchar'> args=[{Const(array): value='{RAIL,SHIP,MAIL}'}, {Func(bool)::bpchareq args=[{Var(bpchar): slot=1, expr='lo_shipmode'}, {Var(bpchar): slot=0, expr='NULL::bpchar'}]}]}
25+
Projection OpCode: {Projection: layout=<2> arg={SaveExpr: <slot=2, type='int8'> arg={Var(int8): kvec=0x3400-5800, expr='lo_orderkey'}}}
26+
Fallback-desc: [<dest='0', expr='lo_orderkey', depth=0:1>, <dest='1', expr='lo_shipmode', depth=0:0>]
27+
CUDA Stack Size: 4448
28+
(12 rows)
29+
30+
-- IN-list with 4 constants should switch to HashedArrayOp
31+
EXPLAIN (verbose, costs off)
32+
SELECT lo_orderkey
33+
FROM lineorder
34+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL','TRUCK');
35+
QUERY PLAN
36+
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
37+
Custom Scan (GpuScan) on public.lineorder
38+
Output: lo_orderkey
39+
GPU Projection: lineorder.lo_orderkey
40+
GPU Scan Quals: (lineorder.lo_shipmode = ANY ('{RAIL,SHIP,MAIL,TRUCK}'::bpchar[]))
41+
KVars-Slot: <slot=0, type='bpchar', expr='lo_shipmode', kv_off=0x0000>, <slot=1, type='int8', expr='lo_orderkey', kv_off=0x3400>
42+
KVecs-Buffer: nbytes: 22528, ndims: 2, items=[kvec0=<0x0000-33ff, type='bpchar', expr='lo_shipmode'>, kvec1=<0x3400-57ff, type='int8', expr='lo_orderkey'>]
43+
LoadVars OpCode: {Packed items[0]={LoadVars(depth=0): kvars=[<slot=1, type='int8' resno=1(lo_orderkey)>, <slot=0, type='bpchar' resno=17(lo_shipmode)>]}}
44+
MoveVars OpCode: {Packed items[0]={MoveVars(depth=0): items=[<slot=1, offset=0x3400-57ff, type='int8', expr='lo_orderkey'>]}}}
45+
Scan Quals OpCode: {HashedArrayOp: nslots=6 hash=(bpchar)[<hash:e99a53ea|TRUCK|t>, <hash:e7d7a8fc|RAIL|t>, <hash:7ad83bf6|MAIL|t>, <hash:b5b0202c|SHIP|t>, <default:f>] arg={Var(bpchar): slot=0, expr='lo_shipmode'}}
46+
Projection OpCode: {Projection: layout=<1> arg={SaveExpr: <slot=1, type='int8'> arg={Var(int8): kvec=0x3400-5800, expr='lo_orderkey'}}}
47+
Fallback-desc: [<dest='0', expr='lo_orderkey', depth=0:1>, <dest='1', expr='lo_shipmode', depth=0:0>]
48+
CUDA Stack Size: 4304
49+
(12 rows)
50+
51+
SET pg_strom.enabled = on;
52+
SELECT lo_orderkey
53+
INTO pg_temp.test01g
54+
FROM lineorder
55+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL','TRUCK')
56+
AND lo_orderkey % 97 = 0;
57+
SET pg_strom.enabled = off;
58+
SELECT lo_orderkey
59+
INTO pg_temp.test01c
60+
FROM lineorder
61+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL','TRUCK')
62+
AND lo_orderkey % 97 = 0;
63+
(SELECT * FROM pg_temp.test01g EXCEPT SELECT * FROM pg_temp.test01c);
64+
lo_orderkey
65+
-------------
66+
(0 rows)
67+
68+
(SELECT * FROM pg_temp.test01c EXCEPT SELECT * FROM pg_temp.test01g);
69+
lo_orderkey
70+
-------------
71+
(0 rows)
72+
73+
-- CASE expr WHEN with 4 branches should switch to HashedArrayOp
74+
SET pg_strom.enabled = on;
75+
EXPLAIN (verbose, costs off)
76+
SELECT lo_linenumber,
77+
CASE lo_linenumber % 5
78+
WHEN 0 THEN 'A'
79+
WHEN 1 THEN 'B'
80+
WHEN 2 THEN 'C'
81+
WHEN 3 THEN 'D'
82+
ELSE 'X'
83+
END AS tag
84+
FROM lineorder
85+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL','TRUCK');
86+
QUERY PLAN
87+
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
88+
Custom Scan (GpuScan) on public.lineorder
89+
Output: lo_linenumber, (CASE (lo_linenumber % 5) WHEN 0 THEN 'A'::text WHEN 1 THEN 'B'::text WHEN 2 THEN 'C'::text WHEN 3 THEN 'D'::text ELSE 'X'::text END)
90+
GPU Projection: lineorder.lo_linenumber, CASE (lineorder.lo_linenumber % 5) WHEN 0 THEN 'A'::text WHEN 1 THEN 'B'::text WHEN 2 THEN 'C'::text WHEN 3 THEN 'D'::text ELSE 'X'::text END
91+
GPU Scan Quals: (lineorder.lo_shipmode = ANY ('{RAIL,SHIP,MAIL,TRUCK}'::bpchar[]))
92+
KVars-Slot: <slot=0, type='bpchar', expr='lo_shipmode', kv_off=0x0000>, <slot=1, type='int4', expr='lo_linenumber', kv_off=0x3400>, <slot=2, type='text', expr='(CASE (lo_linenumber % 5) WHEN 0 THEN 'A'::text WHEN 1 THEN 'B'::text WHEN 2 THEN 'C'::text WHEN 3 THEN 'D'::text ELSE 'X'::text END)'>
93+
KVecs-Buffer: nbytes: 18432, ndims: 2, items=[kvec0=<0x0000-33ff, type='bpchar', expr='lo_shipmode'>, kvec1=<0x3400-47ff, type='int4', expr='lo_linenumber'>]
94+
LoadVars OpCode: {Packed items[0]={LoadVars(depth=0): kvars=[<slot=1, type='int4' resno=2(lo_linenumber)>, <slot=0, type='bpchar' resno=17(lo_shipmode)>]}}
95+
MoveVars OpCode: {Packed items[0]={MoveVars(depth=0): items=[<slot=1, offset=0x3400-47ff, type='int4', expr='lo_linenumber'>]}}}
96+
Scan Quals OpCode: {HashedArrayOp: nslots=6 hash=(bpchar)[<hash:e99a53ea|TRUCK|t>, <hash:e7d7a8fc|RAIL|t>, <hash:7ad83bf6|MAIL|t>, <hash:b5b0202c|SHIP|t>, <default:f>] arg={Var(bpchar): slot=0, expr='lo_shipmode'}}
97+
Projection OpCode: {Projection: layout=<1,2> args=[{SaveExpr: <slot=1, type='int4'> arg={Var(int4): kvec=0x3400-4800, expr='lo_linenumber'}}, {SaveExpr: <slot=2, type='text'> arg={HashedArrayOp: nslots=6 hash=(int4)[<hash:efbec0af|0|A>, <hash:8e731746|1|B>, <hash:fe534f97|3|D>, <hash:439edcf6|2|C>, <default:X>] arg={Func(int4)::int4mod args=[{Var(int4): kvec=0x3400-4800, expr='lo_linenumber'}, {Const(int4): value='5'}]}}}]}
98+
Fallback-desc: [<dest='0', expr='lo_linenumber', depth=0:1>, <dest='2', expr='lo_shipmode', depth=0:0>]
99+
CUDA Stack Size: 4352
100+
(12 rows)
101+
102+
SELECT lo_linenumber,
103+
CASE lo_linenumber % 5
104+
WHEN 0 THEN 'A'
105+
WHEN 1 THEN 'B'
106+
WHEN 2 THEN 'C'
107+
WHEN 3 THEN 'D'
108+
ELSE 'X'
109+
END AS tag
110+
INTO pg_temp.test02g
111+
FROM lineorder
112+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL','TRUCK')
113+
AND lo_orderkey % 97 = 0;
114+
SET pg_strom.enabled = off;
115+
SELECT lo_linenumber,
116+
CASE lo_linenumber % 5
117+
WHEN 0 THEN 'A'
118+
WHEN 1 THEN 'B'
119+
WHEN 2 THEN 'C'
120+
WHEN 3 THEN 'D'
121+
ELSE 'X'
122+
END AS tag
123+
INTO pg_temp.test02c
124+
FROM lineorder
125+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL','TRUCK')
126+
AND lo_orderkey % 97 = 0;
127+
(SELECT * FROM pg_temp.test02g EXCEPT SELECT * FROM pg_temp.test02c);
128+
lo_linenumber | tag
129+
---------------+-----
130+
(0 rows)
131+
132+
(SELECT * FROM pg_temp.test02c EXCEPT SELECT * FROM pg_temp.test02g);
133+
lo_linenumber | tag
134+
---------------+-----
135+
(0 rows)
136+
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
--- Test for HashedArrayOp optimization
3+
---
4+
SET search_path = public;
5+
SET enable_seqscan = off;
6+
SET max_parallel_workers_per_gather = 0;
7+
SET pg_strom.explain_developer_mode = on;
8+
VACUUM ANALYZE lineorder;
9+
-- IN-list with 3 constants keeps ScalarArrayOpAny
10+
EXPLAIN (verbose, costs off)
11+
SELECT lo_orderkey
12+
FROM lineorder
13+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL');
14+
QUERY PLAN
15+
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
16+
Custom Scan (GpuScan) on public.lineorder
17+
Output: lo_orderkey
18+
GPU Projection: lineorder.lo_orderkey
19+
GPU Scan Quals: (lineorder.lo_shipmode = ANY ('{RAIL,SHIP,MAIL}'::bpchar[]))
20+
KVars-Slot: <slot=0, type='bpchar', expr='NULL::bpchar'>, <slot=1, type='bpchar', expr='lo_shipmode', kv_off=0x0000>, <slot=2, type='int8', expr='lo_orderkey', kv_off=0x3400>
21+
KVecs-Buffer: nbytes: 22528, ndims: 2, items=[kvec0=<0x0000-33ff, type='bpchar', expr='lo_shipmode'>, kvec1=<0x3400-57ff, type='int8', expr='lo_orderkey'>]
22+
LoadVars OpCode: {Packed items[0]={LoadVars(depth=0): kvars=[<slot=2, type='int8' resno=1(lo_orderkey)>, <slot=1, type='bpchar' resno=17(lo_shipmode)>]}}
23+
MoveVars OpCode: {Packed items[0]={MoveVars(depth=0): items=[<slot=2, offset=0x3400-57ff, type='int8', expr='lo_orderkey'>]}}}
24+
Scan Quals OpCode: {ScalarArrayOpAny: elem=<slot=0, type='bpchar'> args=[{Const(array): value='{RAIL,SHIP,MAIL}'}, {Func(bool)::bpchareq args=[{Var(bpchar): slot=1, expr='lo_shipmode'}, {Var(bpchar): slot=0, expr='NULL::bpchar'}]}]}
25+
Projection OpCode: {Projection: layout=<2> arg={SaveExpr: <slot=2, type='int8'> arg={Var(int8): kvec=0x3400-5800, expr='lo_orderkey'}}}
26+
Fallback-desc: [<dest='0', expr='lo_orderkey', depth=0:1>, <dest='1', expr='lo_shipmode', depth=0:0>]
27+
CUDA Stack Size: 4448
28+
(12 rows)
29+
30+
-- IN-list with 4 constants should switch to HashedArrayOp
31+
EXPLAIN (verbose, costs off)
32+
SELECT lo_orderkey
33+
FROM lineorder
34+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL','TRUCK');
35+
QUERY PLAN
36+
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
37+
Custom Scan (GpuScan) on public.lineorder
38+
Output: lo_orderkey
39+
GPU Projection: lineorder.lo_orderkey
40+
GPU Scan Quals: (lineorder.lo_shipmode = ANY ('{RAIL,SHIP,MAIL,TRUCK}'::bpchar[]))
41+
KVars-Slot: <slot=0, type='bpchar', expr='lo_shipmode', kv_off=0x0000>, <slot=1, type='int8', expr='lo_orderkey', kv_off=0x3400>
42+
KVecs-Buffer: nbytes: 22528, ndims: 2, items=[kvec0=<0x0000-33ff, type='bpchar', expr='lo_shipmode'>, kvec1=<0x3400-57ff, type='int8', expr='lo_orderkey'>]
43+
LoadVars OpCode: {Packed items[0]={LoadVars(depth=0): kvars=[<slot=1, type='int8' resno=1(lo_orderkey)>, <slot=0, type='bpchar' resno=17(lo_shipmode)>]}}
44+
MoveVars OpCode: {Packed items[0]={MoveVars(depth=0): items=[<slot=1, offset=0x3400-57ff, type='int8', expr='lo_orderkey'>]}}}
45+
Scan Quals OpCode: {HashedArrayOp: nslots=6 hash=(bpchar)[<hash:e99a53ea|TRUCK|t>, <hash:e7d7a8fc|RAIL|t>, <hash:7ad83bf6|MAIL|t>, <hash:b5b0202c|SHIP|t>, <default:f>] arg={Var(bpchar): slot=0, expr='lo_shipmode'}}
46+
Projection OpCode: {Projection: layout=<1> arg={SaveExpr: <slot=1, type='int8'> arg={Var(int8): kvec=0x3400-5800, expr='lo_orderkey'}}}
47+
Fallback-desc: [<dest='0', expr='lo_orderkey', depth=0:1>, <dest='1', expr='lo_shipmode', depth=0:0>]
48+
CUDA Stack Size: 4304
49+
(12 rows)
50+
51+
SET pg_strom.enabled = on;
52+
SELECT lo_orderkey
53+
INTO pg_temp.test01g
54+
FROM lineorder
55+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL','TRUCK')
56+
AND lo_orderkey % 97 = 0;
57+
SET pg_strom.enabled = off;
58+
SELECT lo_orderkey
59+
INTO pg_temp.test01c
60+
FROM lineorder
61+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL','TRUCK')
62+
AND lo_orderkey % 97 = 0;
63+
(SELECT * FROM pg_temp.test01g EXCEPT SELECT * FROM pg_temp.test01c);
64+
lo_orderkey
65+
-------------
66+
(0 rows)
67+
68+
(SELECT * FROM pg_temp.test01c EXCEPT SELECT * FROM pg_temp.test01g);
69+
lo_orderkey
70+
-------------
71+
(0 rows)
72+
73+
-- CASE expr WHEN with 4 branches should switch to HashedArrayOp
74+
SET pg_strom.enabled = on;
75+
EXPLAIN (verbose, costs off)
76+
SELECT lo_linenumber,
77+
CASE lo_linenumber % 5
78+
WHEN 0 THEN 'A'
79+
WHEN 1 THEN 'B'
80+
WHEN 2 THEN 'C'
81+
WHEN 3 THEN 'D'
82+
ELSE 'X'
83+
END AS tag
84+
FROM lineorder
85+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL','TRUCK');
86+
QUERY PLAN
87+
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
88+
Custom Scan (GpuScan) on public.lineorder
89+
Output: lo_linenumber, (CASE (lo_linenumber % 5) WHEN 0 THEN 'A'::text WHEN 1 THEN 'B'::text WHEN 2 THEN 'C'::text WHEN 3 THEN 'D'::text ELSE 'X'::text END)
90+
GPU Projection: lineorder.lo_linenumber, CASE (lineorder.lo_linenumber % 5) WHEN 0 THEN 'A'::text WHEN 1 THEN 'B'::text WHEN 2 THEN 'C'::text WHEN 3 THEN 'D'::text ELSE 'X'::text END
91+
GPU Scan Quals: (lineorder.lo_shipmode = ANY ('{RAIL,SHIP,MAIL,TRUCK}'::bpchar[]))
92+
KVars-Slot: <slot=0, type='bpchar', expr='lo_shipmode', kv_off=0x0000>, <slot=1, type='int4', expr='lo_linenumber', kv_off=0x3400>, <slot=2, type='text', expr='(CASE (lo_linenumber % 5) WHEN 0 THEN 'A'::text WHEN 1 THEN 'B'::text WHEN 2 THEN 'C'::text WHEN 3 THEN 'D'::text ELSE 'X'::text END)'>
93+
KVecs-Buffer: nbytes: 18432, ndims: 2, items=[kvec0=<0x0000-33ff, type='bpchar', expr='lo_shipmode'>, kvec1=<0x3400-47ff, type='int4', expr='lo_linenumber'>]
94+
LoadVars OpCode: {Packed items[0]={LoadVars(depth=0): kvars=[<slot=1, type='int4' resno=2(lo_linenumber)>, <slot=0, type='bpchar' resno=17(lo_shipmode)>]}}
95+
MoveVars OpCode: {Packed items[0]={MoveVars(depth=0): items=[<slot=1, offset=0x3400-47ff, type='int4', expr='lo_linenumber'>]}}}
96+
Scan Quals OpCode: {HashedArrayOp: nslots=6 hash=(bpchar)[<hash:e99a53ea|TRUCK|t>, <hash:e7d7a8fc|RAIL|t>, <hash:7ad83bf6|MAIL|t>, <hash:b5b0202c|SHIP|t>, <default:f>] arg={Var(bpchar): slot=0, expr='lo_shipmode'}}
97+
Projection OpCode: {Projection: layout=<1,2> args=[{SaveExpr: <slot=1, type='int4'> arg={Var(int4): kvec=0x3400-4800, expr='lo_linenumber'}}, {SaveExpr: <slot=2, type='text'> arg={HashedArrayOp: nslots=6 hash=(int4)[<hash:efbec0af|0|A>, <hash:8e731746|1|B>, <hash:fe534f97|3|D>, <hash:439edcf6|2|C>, <default:X>] arg={Func(int4)::int4mod args=[{Var(int4): kvec=0x3400-4800, expr='lo_linenumber'}, {Const(int4): value='5'}]}}}]}
98+
Fallback-desc: [<dest='0', expr='lo_linenumber', depth=0:1>, <dest='2', expr='lo_shipmode', depth=0:0>]
99+
CUDA Stack Size: 4352
100+
(12 rows)
101+
102+
SELECT lo_linenumber,
103+
CASE lo_linenumber % 5
104+
WHEN 0 THEN 'A'
105+
WHEN 1 THEN 'B'
106+
WHEN 2 THEN 'C'
107+
WHEN 3 THEN 'D'
108+
ELSE 'X'
109+
END AS tag
110+
INTO pg_temp.test02g
111+
FROM lineorder
112+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL','TRUCK')
113+
AND lo_orderkey % 97 = 0;
114+
SET pg_strom.enabled = off;
115+
SELECT lo_linenumber,
116+
CASE lo_linenumber % 5
117+
WHEN 0 THEN 'A'
118+
WHEN 1 THEN 'B'
119+
WHEN 2 THEN 'C'
120+
WHEN 3 THEN 'D'
121+
ELSE 'X'
122+
END AS tag
123+
INTO pg_temp.test02c
124+
FROM lineorder
125+
WHERE lo_shipmode IN ('RAIL','SHIP','MAIL','TRUCK')
126+
AND lo_orderkey % 97 = 0;
127+
(SELECT * FROM pg_temp.test02g EXCEPT SELECT * FROM pg_temp.test02c);
128+
lo_linenumber | tag
129+
---------------+-----
130+
(0 rows)
131+
132+
(SELECT * FROM pg_temp.test02c EXCEPT SELECT * FROM pg_temp.test02g);
133+
lo_linenumber | tag
134+
---------------+-----
135+
(0 rows)
136+

0 commit comments

Comments
 (0)