From f2c7c21b911d86718e856b4927fb3bfcf42a79f2 Mon Sep 17 00:00:00 2001 From: zhaosen Date: Tue, 16 Jul 2024 17:24:57 +0800 Subject: [PATCH] =?UTF-8?q?ustore=20seq=20scan=20=E5=B9=B6=E8=A1=8CSMP?= =?UTF-8?q?=E7=9A=84regress=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../regress/expected/smp_seq_scan_ustore.out | 1412 +++++++++++++++++ src/test/regress/sql/smp_seq_scan_ustore.sql | 208 +++ 2 files changed, 1620 insertions(+) create mode 100644 src/test/regress/expected/smp_seq_scan_ustore.out create mode 100644 src/test/regress/sql/smp_seq_scan_ustore.sql diff --git a/src/test/regress/expected/smp_seq_scan_ustore.out b/src/test/regress/expected/smp_seq_scan_ustore.out new file mode 100644 index 0000000000..9e6e341328 --- /dev/null +++ b/src/test/regress/expected/smp_seq_scan_ustore.out @@ -0,0 +1,1412 @@ +create schema test_smp; +set search_path=test_smp; +create table t1(a int, b int, c int, d bigint) with(storage_type=ustore); +insert into t1 values(generate_series(1, 100), generate_series(1, 10), generate_series(1, 2), generate_series(1, 50)); +create table t2(a int, b int) with(storage_type=ustore); +insert into t2 values(generate_series(1, 10), generate_series(1, 30)); +create table t3(a int, b int, c int) with(storage_type=ustore); +insert into t3 values(generate_series(1, 50), generate_series(1, 100), generate_series(1, 10)); +analyze t1; +analyze t2; +analyze t3; +set query_dop=1002; +explain (costs off) select * from t2 order by 1,2; + QUERY PLAN +---------------------------------------------- + Sort + Sort Key: a, b + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Seq Scan on t2 +(4 rows) + +select * from t2 order by 1,2; + a | b +----+---- + 1 | 1 + 1 | 11 + 1 | 21 + 2 | 2 + 2 | 12 + 2 | 22 + 3 | 3 + 3 | 13 + 3 | 23 + 4 | 4 + 4 | 14 + 4 | 24 + 5 | 5 + 5 | 15 + 5 | 25 + 6 | 6 + 6 | 16 + 6 | 26 + 7 | 7 + 7 | 17 + 7 | 27 + 8 | 8 + 8 | 18 + 8 | 28 + 9 | 9 + 9 | 19 + 9 | 29 + 10 | 10 + 10 | 20 + 10 | 30 +(30 rows) + +set enable_nestloop=on; +set enable_mergejoin=off; +set enable_hashjoin=off; +explain (costs off) select t1.a,t2.b from t1, t2 where t1.a = t2.a order by 1,2; + QUERY PLAN +---------------------------------------------------------------------- + Sort + Sort Key: t1.a, t2.b + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Nested Loop + Join Filter: (t1.a = t2.a) + -> Streaming(type: LOCAL REDISTRIBUTE dop: 2/2) + -> Seq Scan on t1 + -> Materialize + -> Streaming(type: LOCAL REDISTRIBUTE dop: 2/2) + -> Seq Scan on t2 +(10 rows) + +select t1.a,t2.b from t1, t2 where t1.a = t2.a order by 1,2; + a | b +----+---- + 1 | 1 + 1 | 11 + 1 | 21 + 2 | 2 + 2 | 12 + 2 | 22 + 3 | 3 + 3 | 13 + 3 | 23 + 4 | 4 + 4 | 14 + 4 | 24 + 5 | 5 + 5 | 15 + 5 | 25 + 6 | 6 + 6 | 16 + 6 | 26 + 7 | 7 + 7 | 17 + 7 | 27 + 8 | 8 + 8 | 18 + 8 | 28 + 9 | 9 + 9 | 19 + 9 | 29 + 10 | 10 + 10 | 20 + 10 | 30 +(30 rows) + +set enable_nestloop=off; +set enable_hashjoin=on; +explain (costs off) select t1.a,t2.b,t3.c from t1, t2, t3 where t1.a = t2.a and t1.b = t3.c order by 1,2,3; + QUERY PLAN +------------------------------------------------------------------------------- + Sort + Sort Key: t1.a, t2.b, t3.c + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Hash Join + Hash Cond: (t3.c = t1.b) + -> Seq Scan on t3 + -> Hash + -> Streaming(type: BROADCAST dop: 2/2) + -> Hash Join + Hash Cond: (t1.a = t2.a) + -> Seq Scan on t1 + -> Hash + -> Streaming(type: BROADCAST dop: 2/2) + -> Seq Scan on t2 +(14 rows)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 | 19 | 9 + 9 | 19 | 9 + 9 | 19 | 9 + 9 | 19 | 9 + 9 | 19 | 9 + 9 | 19 | 9 + 9 | 19 | 9 + 9 | 19 | 9 + 9 | 19 | 9 + 9 | 19 | 9 + 9 | 29 | 9 + 9 | 29 | 9 + 9 | 29 | 9 + 9 | 29 | 9 + 9 | 29 | 9 + 9 | 29 | 9 + 9 | 29 | 9 + 9 | 29 | 9 + 9 | 29 | 9 + 9 | 29 | 9 + 10 | 10 | 10 + 10 | 10 | 10 + 10 | 10 | 10 + 10 | 10 | 10 + 10 | 10 | 10 + 10 | 10 | 10 + 10 | 10 | 10 + 10 | 10 | 10 + 10 | 10 | 10 + 10 | 10 | 10 + 10 | 20 | 10 + 10 | 20 | 10 + 10 | 20 | 10 + 10 | 20 | 10 + 10 | 20 | 10 + 10 | 20 | 10 + 10 | 20 | 10 + 10 | 20 | 10 + 10 | 20 | 10 + 10 | 20 | 10 + 10 | 30 | 10 + 10 | 30 | 10 + 10 | 30 | 10 + 10 | 30 | 10 + 10 | 30 | 10 + 10 | 30 | 10 + 10 | 30 | 10 + 10 | 30 | 10 + 10 | 30 | 10 + 10 | 30 | 10 +(300 rows) + +set enable_nestloop=on; +explain (costs off) select a, avg(b), sum(c) from t1 group by a order by 1,2,3; + QUERY PLAN +---------------------------------------------------------------- + Sort + Sort Key: a, (avg(b)), (sum(c)) + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> HashAggregate + Group By Key: a + -> Streaming(type: LOCAL REDISTRIBUTE dop: 2/2) + -> Seq Scan on t1 +(7 rows) + +select a, avg(b), sum(c) from t1 group by a order by 1,2,3; + a | avg | sum +-----+------------------------+----- + 1 | 1.00000000000000000000 | 1 + 2 | 2.0000000000000000 | 2 + 3 | 3.0000000000000000 | 1 + 4 | 4.0000000000000000 | 2 + 5 | 5.0000000000000000 | 1 + 6 | 6.0000000000000000 | 2 + 7 | 7.0000000000000000 | 1 + 8 | 8.0000000000000000 | 2 + 9 | 9.0000000000000000 | 1 + 10 | 10.0000000000000000 | 2 + 11 | 1.00000000000000000000 | 1 + 12 | 2.0000000000000000 | 2 + 13 | 3.0000000000000000 | 1 + 14 | 4.0000000000000000 | 2 + 15 | 5.0000000000000000 | 1 + 16 | 6.0000000000000000 | 2 + 17 | 7.0000000000000000 | 1 + 18 | 8.0000000000000000 | 2 + 19 | 9.0000000000000000 | 1 + 20 | 10.0000000000000000 | 2 + 21 | 1.00000000000000000000 | 1 + 22 | 2.0000000000000000 | 2 + 23 | 3.0000000000000000 | 1 + 24 | 4.0000000000000000 | 2 + 25 | 5.0000000000000000 | 1 + 26 | 6.0000000000000000 | 2 + 27 | 7.0000000000000000 | 1 + 28 | 8.0000000000000000 | 2 + 29 | 9.0000000000000000 | 1 + 30 | 10.0000000000000000 | 2 + 31 | 1.00000000000000000000 | 1 + 32 | 2.0000000000000000 | 2 + 33 | 3.0000000000000000 | 1 + 34 | 4.0000000000000000 | 2 + 35 | 5.0000000000000000 | 1 + 36 | 6.0000000000000000 | 2 + 37 | 7.0000000000000000 | 1 + 38 | 8.0000000000000000 | 2 + 39 | 9.0000000000000000 | 1 + 40 | 10.0000000000000000 | 2 + 41 | 1.00000000000000000000 | 1 + 42 | 2.0000000000000000 | 2 + 43 | 3.0000000000000000 | 1 + 44 | 4.0000000000000000 | 2 + 45 | 5.0000000000000000 | 1 + 46 | 6.0000000000000000 | 2 + 47 | 7.0000000000000000 | 1 + 48 | 8.0000000000000000 | 2 + 49 | 9.0000000000000000 | 1 + 50 | 10.0000000000000000 | 2 + 51 | 1.00000000000000000000 | 1 + 52 | 2.0000000000000000 | 2 + 53 | 3.0000000000000000 | 1 + 54 | 4.0000000000000000 | 2 + 55 | 5.0000000000000000 | 1 + 56 | 6.0000000000000000 | 2 + 57 | 7.0000000000000000 | 1 + 58 | 8.0000000000000000 | 2 + 59 | 9.0000000000000000 | 1 + 60 | 10.0000000000000000 | 2 + 61 | 1.00000000000000000000 | 1 + 62 | 2.0000000000000000 | 2 + 63 | 3.0000000000000000 | 1 + 64 | 4.0000000000000000 | 2 + 65 | 5.0000000000000000 | 1 + 66 | 6.0000000000000000 | 2 + 67 | 7.0000000000000000 | 1 + 68 | 8.0000000000000000 | 2 + 69 | 9.0000000000000000 | 1 + 70 | 10.0000000000000000 | 2 + 71 | 1.00000000000000000000 | 1 + 72 | 2.0000000000000000 | 2 + 73 | 3.0000000000000000 | 1 + 74 | 4.0000000000000000 | 2 + 75 | 5.0000000000000000 | 1 + 76 | 6.0000000000000000 | 2 + 77 | 7.0000000000000000 | 1 + 78 | 8.0000000000000000 | 2 + 79 | 9.0000000000000000 | 1 + 80 | 10.0000000000000000 | 2 + 81 | 1.00000000000000000000 | 1 + 82 | 2.0000000000000000 | 2 + 83 | 3.0000000000000000 | 1 + 84 | 4.0000000000000000 | 2 + 85 | 5.0000000000000000 | 1 + 86 | 6.0000000000000000 | 2 + 87 | 7.0000000000000000 | 1 + 88 | 8.0000000000000000 | 2 + 89 | 9.0000000000000000 | 1 + 90 | 10.0000000000000000 | 2 + 91 | 1.00000000000000000000 | 1 + 92 | 2.0000000000000000 | 2 + 93 | 3.0000000000000000 | 1 + 94 | 4.0000000000000000 | 2 + 95 | 5.0000000000000000 | 1 + 96 | 6.0000000000000000 | 2 + 97 | 7.0000000000000000 | 1 + 98 | 8.0000000000000000 | 2 + 99 | 9.0000000000000000 | 1 + 100 | 10.0000000000000000 | 2 +(100 rows) + +explain (costs off) select median(a) from t1; + QUERY PLAN +---------------------- + Aggregate + -> Seq Scan on t1 +(2 rows) + +select median(a) from t1; + median +-------- + 50.5 +(1 row) + +explain (costs off) select first(a) from t1; + QUERY PLAN +---------------------- + Aggregate + -> Seq Scan on t1 +(2 rows) + +select first(a) from t1; + first +------- + 1 +(1 row) + +explain (costs off) select sum(b)+median(a) as result from t1; + QUERY PLAN +---------------------- + Aggregate + -> Seq Scan on t1 +(2 rows) + +select sum(b)+median(a) as result from t1; + result +-------- + 600.5 +(1 row) + +explain (costs off) select a, count(distinct b) from t1 group by a order by 1 limit 10; + QUERY PLAN +---------------------------------------------------------------------------------------- + Limit + -> Sort + Sort Key: a + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Limit + -> Sort + Sort Key: a + -> GroupAggregate + Group By Key: a + -> Sort + Sort Key: a + -> Streaming(type: LOCAL REDISTRIBUTE dop: 2/2) + -> Seq Scan on t1 +(13 rows) + +select a, count(distinct b) from t1 group by a order by 1 limit 10; + a | count +----+------- + 1 | 1 + 2 | 1 + 3 | 1 + 4 | 1 + 5 | 1 + 6 | 1 + 7 | 1 + 8 | 1 + 9 | 1 + 10 | 1 +(10 rows) + +explain (costs off) select count(distinct b), count(distinct c) from t1 limit 10; + QUERY PLAN +---------------------------------------------------------------------------------------- + Limit + -> Nested Loop + -> Aggregate + -> Streaming(type: BROADCAST dop: 1/2) + -> Aggregate + -> HashAggregate + Group By Key: test_smp.t1.b + -> Streaming(type: LOCAL REDISTRIBUTE dop: 2/2) + -> HashAggregate + Group By Key: test_smp.t1.b + -> Seq Scan on t1 + -> Materialize + -> Aggregate + -> Streaming(type: BROADCAST dop: 1/2) + -> Aggregate + -> HashAggregate + Group By Key: test_smp.t1.c + -> Streaming(type: LOCAL REDISTRIBUTE dop: 2/2) + -> HashAggregate + Group By Key: test_smp.t1.c + -> Seq Scan on t1 +(21 rows) + +select count(distinct b), count(distinct c) from t1 limit 10; + count | count +-------+------- + 10 | 2 +(1 row) + +explain (costs off) select distinct b from t1 union all select distinct a from t2 order by 1; + QUERY PLAN +---------------------------------------------------------------------------- + Sort + Sort Key: t1.b + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Result + -> Append + -> HashAggregate + Group By Key: t1.b + -> Streaming(type: LOCAL REDISTRIBUTE dop: 2/2) + -> HashAggregate + Group By Key: t1.b + -> Seq Scan on t1 + -> HashAggregate + Group By Key: t2.a + -> Streaming(type: LOCAL REDISTRIBUTE dop: 2/2) + -> HashAggregate + Group By Key: t2.a + -> Seq Scan on t2 +(17 rows) + +select distinct b from t1 union all select distinct a from t2 order by 1; + b +---- + 1 + 1 + 2 + 2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 + 7 + 8 + 8 + 9 + 9 + 10 + 10 +(20 rows) + +explain (costs off) select * from t1 where t1.a in (select t2.a from t2, t3 where t2.b = t3.c) order by 1,2,3; + QUERY PLAN +------------------------------------------------------------------------------------------- + Sort + Sort Key: t1.a, t1.b, t1.c + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Hash Join + Hash Cond: (t1.a = t2.a) + -> Seq Scan on t1 + -> Hash + -> HashAggregate + Group By Key: t2.a + -> Streaming(type: BROADCAST dop: 2/2) + -> HashAggregate + Group By Key: t2.a + -> Hash Join + Hash Cond: (t3.c = t2.b) + -> Seq Scan on t3 + -> Hash + -> Streaming(type: BROADCAST dop: 2/2) + -> Seq Scan on t2 +(18 rows) + +select * from t1 where t1.a in (select t2.a from t2, t3 where t2.b = t3.c) order by 1,2,3; + a | b | c | d +----+----+---+---- + 1 | 1 | 1 | 1 + 2 | 2 | 2 | 2 + 3 | 3 | 1 | 3 + 4 | 4 | 2 | 4 + 5 | 5 | 1 | 5 + 6 | 6 | 2 | 6 + 7 | 7 | 1 | 7 + 8 | 8 | 2 | 8 + 9 | 9 | 1 | 9 + 10 | 10 | 2 | 10 +(10 rows) + +explain (costs off) with s1 as (select t1.a as a, t3.b as b from t1,t3 where t1.b=t3.c) select * from t2, s1 where t2.b=s1.a order by 1,2,3,4; + QUERY PLAN +------------------------------------------------------------------------------- + Sort + Sort Key: t2.a, t2.b, t3.b + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Hash Join + Hash Cond: (t3.c = t1.b) + -> Seq Scan on t3 + -> Hash + -> Streaming(type: BROADCAST dop: 2/2) + -> Hash Join + Hash Cond: (t1.a = t2.b) + -> Seq Scan on t1 + -> Hash + -> Streaming(type: BROADCAST dop: 2/2) + -> Seq Scan on t2 +(14 rows) + +with s1 as (select t1.a as a, t3.b as b from t1,t3 where t1.b=t3.c) select * from t2, s1 where t2.b=s1.a order by 1,2,3,4; + a | b | a | b +----+----+----+----- + 1 | 1 | 1 | 1 + 1 | 1 | 1 | 11 + 1 | 1 | 1 | 21 + 1 | 1 | 1 | 31 + 1 | 1 | 1 | 41 + 1 | 1 | 1 | 51 + 1 | 1 | 1 | 61 + 1 | 1 | 1 | 71 + 1 | 1 | 1 | 81 + 1 | 1 | 1 | 91 + 1 | 11 | 11 | 1 + 1 | 11 | 11 | 11 + 1 | 11 | 11 | 21 + 1 | 11 | 11 | 31 + 1 | 11 | 11 | 41 + 1 | 11 | 11 | 51 + 1 | 11 | 11 | 61 + 1 | 11 | 11 | 71 + 1 | 11 | 11 | 81 + 1 | 11 | 11 | 91 + 1 | 21 | 21 | 1 + 1 | 21 | 21 | 11 + 1 | 21 | 21 | 21 + 1 | 21 | 21 | 31 + 1 | 21 | 21 | 41 + 1 | 21 | 21 | 51 + 1 | 21 | 21 | 61 + 1 | 21 | 21 | 71 + 1 | 21 | 21 | 81 + 1 | 21 | 21 | 91 + 2 | 2 | 2 | 2 + 2 | 2 | 2 | 12 + 2 | 2 | 2 | 22 + 2 | 2 | 2 | 32 + 2 | 2 | 2 | 42 + 2 | 2 | 2 | 52 + 2 | 2 | 2 | 62 + 2 | 2 | 2 | 72 + 2 | 2 | 2 | 82 + 2 | 2 | 2 | 92 + 2 | 12 | 12 | 2 + 2 | 12 | 12 | 12 + 2 | 12 | 12 | 22 + 2 | 12 | 12 | 32 + 2 | 12 | 12 | 42 + 2 | 12 | 12 | 52 + 2 | 12 | 12 | 62 + 2 | 12 | 12 | 72 + 2 | 12 | 12 | 82 + 2 | 12 | 12 | 92 + 2 | 22 | 22 | 2 + 2 | 22 | 22 | 12 + 2 | 22 | 22 | 22 + 2 | 22 | 22 | 32 + 2 | 22 | 22 | 42 + 2 | 22 | 22 | 52 + 2 | 22 | 22 | 62 + 2 | 22 | 22 | 72 + 2 | 22 | 22 | 82 + 2 | 22 | 22 | 92 + 3 | 3 | 3 | 3 + 3 | 3 | 3 | 13 + 3 | 3 | 3 | 23 + 3 | 3 | 3 | 33 + 3 | 3 | 3 | 43 + 3 | 3 | 3 | 53 + 3 | 3 | 3 | 63 + 3 | 3 | 3 | 73 + 3 | 3 | 3 | 83 + 3 | 3 | 3 | 93 + 3 | 13 | 13 | 3 + 3 | 13 | 13 | 13 + 3 | 13 | 13 | 23 + 3 | 13 | 13 | 33 + 3 | 13 | 13 | 43 + 3 | 13 | 13 | 53 + 3 | 13 | 13 | 63 + 3 | 13 | 13 | 73 + 3 | 13 | 13 | 83 + 3 | 13 | 13 | 93 + 3 | 23 | 23 | 3 + 3 | 23 | 23 | 13 + 3 | 23 | 23 | 23 + 3 | 23 | 23 | 33 + 3 | 23 | 23 | 43 + 3 | 23 | 23 | 53 + 3 | 23 | 23 | 63 + 3 | 23 | 23 | 73 + 3 | 23 | 23 | 83 + 3 | 23 | 23 | 93 + 4 | 4 | 4 | 4 + 4 | 4 | 4 | 14 + 4 | 4 | 4 | 24 + 4 | 4 | 4 | 34 + 4 | 4 | 4 | 44 + 4 | 4 | 4 | 54 + 4 | 4 | 4 | 64 + 4 | 4 | 4 | 74 + 4 | 4 | 4 | 84 + 4 | 4 | 4 | 94 + 4 | 14 | 14 | 4 + 4 | 14 | 14 | 14 + 4 | 14 | 14 | 24 + 4 | 14 | 14 | 34 + 4 | 14 | 14 | 44 + 4 | 14 | 14 | 54 + 4 | 14 | 14 | 64 + 4 | 14 | 14 | 74 + 4 | 14 | 14 | 84 + 4 | 14 | 14 | 94 + 4 | 24 | 24 | 4 + 4 | 24 | 24 | 14 + 4 | 24 | 24 | 24 + 4 | 24 | 24 | 34 + 4 | 24 | 24 | 44 + 4 | 24 | 24 | 54 + 4 | 24 | 24 | 64 + 4 | 24 | 24 | 74 + 4 | 24 | 24 | 84 + 4 | 24 | 24 | 94 + 5 | 5 | 5 | 5 + 5 | 5 | 5 | 15 + 5 | 5 | 5 | 25 + 5 | 5 | 5 | 35 + 5 | 5 | 5 | 45 + 5 | 5 | 5 | 55 + 5 | 5 | 5 | 65 + 5 | 5 | 5 | 75 + 5 | 5 | 5 | 85 + 5 | 5 | 5 | 95 + 5 | 15 | 15 | 5 + 5 | 15 | 15 | 15 + 5 | 15 | 15 | 25 + 5 | 15 | 15 | 35 + 5 | 15 | 15 | 45 + 5 | 15 | 15 | 55 + 5 | 15 | 15 | 65 + 5 | 15 | 15 | 75 + 5 | 15 | 15 | 85 + 5 | 15 | 15 | 95 + 5 | 25 | 25 | 5 + 5 | 25 | 25 | 15 + 5 | 25 | 25 | 25 + 5 | 25 | 25 | 35 + 5 | 25 | 25 | 45 + 5 | 25 | 25 | 55 + 5 | 25 | 25 | 65 + 5 | 25 | 25 | 75 + 5 | 25 | 25 | 85 + 5 | 25 | 25 | 95 + 6 | 6 | 6 | 6 + 6 | 6 | 6 | 16 + 6 | 6 | 6 | 26 + 6 | 6 | 6 | 36 + 6 | 6 | 6 | 46 + 6 | 6 | 6 | 56 + 6 | 6 | 6 | 66 + 6 | 6 | 6 | 76 + 6 | 6 | 6 | 86 + 6 | 6 | 6 | 96 + 6 | 16 | 16 | 6 + 6 | 16 | 16 | 16 + 6 | 16 | 16 | 26 + 6 | 16 | 16 | 36 + 6 | 16 | 16 | 46 + 6 | 16 | 16 | 56 + 6 | 16 | 16 | 66 + 6 | 16 | 16 | 76 + 6 | 16 | 16 | 86 + 6 | 16 | 16 | 96 + 6 | 26 | 26 | 6 + 6 | 26 | 26 | 16 + 6 | 26 | 26 | 26 + 6 | 26 | 26 | 36 + 6 | 26 | 26 | 46 + 6 | 26 | 26 | 56 + 6 | 26 | 26 | 66 + 6 | 26 | 26 | 76 + 6 | 26 | 26 | 86 + 6 | 26 | 26 | 96 + 7 | 7 | 7 | 7 + 7 | 7 | 7 | 17 + 7 | 7 | 7 | 27 + 7 | 7 | 7 | 37 + 7 | 7 | 7 | 47 + 7 | 7 | 7 | 57 + 7 | 7 | 7 | 67 + 7 | 7 | 7 | 77 + 7 | 7 | 7 | 87 + 7 | 7 | 7 | 97 + 7 | 17 | 17 | 7 + 7 | 17 | 17 | 17 + 7 | 17 | 17 | 27 + 7 | 17 | 17 | 37 + 7 | 17 | 17 | 47 + 7 | 17 | 17 | 57 + 7 | 17 | 17 | 67 + 7 | 17 | 17 | 77 + 7 | 17 | 17 | 87 + 7 | 17 | 17 | 97 + 7 | 27 | 27 | 7 + 7 | 27 | 27 | 17 + 7 | 27 | 27 | 27 + 7 | 27 | 27 | 37 + 7 | 27 | 27 | 47 + 7 | 27 | 27 | 57 + 7 | 27 | 27 | 67 + 7 | 27 | 27 | 77 + 7 | 27 | 27 | 87 + 7 | 27 | 27 | 97 + 8 | 8 | 8 | 8 + 8 | 8 | 8 | 18 + 8 | 8 | 8 | 28 + 8 | 8 | 8 | 38 + 8 | 8 | 8 | 48 + 8 | 8 | 8 | 58 + 8 | 8 | 8 | 68 + 8 | 8 | 8 | 78 + 8 | 8 | 8 | 88 + 8 | 8 | 8 | 98 + 8 | 18 | 18 | 8 + 8 | 18 | 18 | 18 + 8 | 18 | 18 | 28 + 8 | 18 | 18 | 38 + 8 | 18 | 18 | 48 + 8 | 18 | 18 | 58 + 8 | 18 | 18 | 68 + 8 | 18 | 18 | 78 + 8 | 18 | 18 | 88 + 8 | 18 | 18 | 98 + 8 | 28 | 28 | 8 + 8 | 28 | 28 | 18 + 8 | 28 | 28 | 28 + 8 | 28 | 28 | 38 + 8 | 28 | 28 | 48 + 8 | 28 | 28 | 58 + 8 | 28 | 28 | 68 + 8 | 28 | 28 | 78 + 8 | 28 | 28 | 88 + 8 | 28 | 28 | 98 + 9 | 9 | 9 | 9 + 9 | 9 | 9 | 19 + 9 | 9 | 9 | 29 + 9 | 9 | 9 | 39 + 9 | 9 | 9 | 49 + 9 | 9 | 9 | 59 + 9 | 9 | 9 | 69 + 9 | 9 | 9 | 79 + 9 | 9 | 9 | 89 + 9 | 9 | 9 | 99 + 9 | 19 | 19 | 9 + 9 | 19 | 19 | 19 + 9 | 19 | 19 | 29 + 9 | 19 | 19 | 39 + 9 | 19 | 19 | 49 + 9 | 19 | 19 | 59 + 9 | 19 | 19 | 69 + 9 | 19 | 19 | 79 + 9 | 19 | 19 | 89 + 9 | 19 | 19 | 99 + 9 | 29 | 29 | 9 + 9 | 29 | 29 | 19 + 9 | 29 | 29 | 29 + 9 | 29 | 29 | 39 + 9 | 29 | 29 | 49 + 9 | 29 | 29 | 59 + 9 | 29 | 29 | 69 + 9 | 29 | 29 | 79 + 9 | 29 | 29 | 89 + 9 | 29 | 29 | 99 + 10 | 10 | 10 | 10 + 10 | 10 | 10 | 20 + 10 | 10 | 10 | 30 + 10 | 10 | 10 | 40 + 10 | 10 | 10 | 50 + 10 | 10 | 10 | 60 + 10 | 10 | 10 | 70 + 10 | 10 | 10 | 80 + 10 | 10 | 10 | 90 + 10 | 10 | 10 | 100 + 10 | 20 | 20 | 10 + 10 | 20 | 20 | 20 + 10 | 20 | 20 | 30 + 10 | 20 | 20 | 40 + 10 | 20 | 20 | 50 + 10 | 20 | 20 | 60 + 10 | 20 | 20 | 70 + 10 | 20 | 20 | 80 + 10 | 20 | 20 | 90 + 10 | 20 | 20 | 100 + 10 | 30 | 30 | 10 + 10 | 30 | 30 | 20 + 10 | 30 | 30 | 30 + 10 | 30 | 30 | 40 + 10 | 30 | 30 | 50 + 10 | 30 | 30 | 60 + 10 | 30 | 30 | 70 + 10 | 30 | 30 | 80 + 10 | 30 | 30 | 90 + 10 | 30 | 30 | 100 +(300 rows) + +explain (costs off) select * from t1 order by a limit 10; + QUERY PLAN +---------------------------------------------------- + Limit + -> Sort + Sort Key: a + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Limit + -> Sort + Sort Key: a + -> Seq Scan on t1 +(8 rows) + +select * from t1 order by a limit 10; + a | b | c | d +----+----+---+---- + 1 | 1 | 1 | 1 + 2 | 2 | 2 | 2 + 3 | 3 | 1 | 3 + 4 | 4 | 2 | 4 + 5 | 5 | 1 | 5 + 6 | 6 | 2 | 6 + 7 | 7 | 1 | 7 + 8 | 8 | 2 | 8 + 9 | 9 | 1 | 9 + 10 | 10 | 2 | 10 +(10 rows) + +explain (costs off) select * from t1 order by a limit 10 offset 20; + QUERY PLAN +---------------------------------------------------------- + Limit + -> Limit + -> Sort + Sort Key: a + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Limit + -> Sort + Sort Key: a + -> Seq Scan on t1 +(9 rows) + +select * from t1 order by a limit 10 offset 20; + a | b | c | d +----+----+---+---- + 21 | 1 | 1 | 21 + 22 | 2 | 2 | 22 + 23 | 3 | 1 | 23 + 24 | 4 | 2 | 24 + 25 | 5 | 1 | 25 + 26 | 6 | 2 | 26 + 27 | 7 | 1 | 27 + 28 | 8 | 2 | 28 + 29 | 9 | 1 | 29 + 30 | 10 | 2 | 30 +(10 rows) + +-- test limit and offset +explain (costs off) select * from t1 limit 1; + QUERY PLAN +---------------------------------------------- + Limit + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Limit + -> Seq Scan on t1 +(4 rows) + +explain (costs off) select * from t1 limit 1 offset 10; + QUERY PLAN +---------------------------------------------------- + Limit + -> Limit + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Limit + -> Seq Scan on t1 +(5 rows) + +explain (costs off) select * from t1 order by 1 limit 1 offset 10; + QUERY PLAN +---------------------------------------------------------- + Limit + -> Limit + -> Sort + Sort Key: a + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Limit + -> Sort + Sort Key: a + -> Seq Scan on t1 +(9 rows) + +-- test subquery recursive +explain (costs off) select * from (select a, rownum as row from (select a from t3) where rownum <= 10) where row >=5; + QUERY PLAN +--------------------------------------------- + Subquery Scan on __unnamed_subquery__ + Filter: (__unnamed_subquery__."row" >= 5) + -> Limit + -> Seq Scan on t3 +(4 rows) + +select * from (select a, rownum as row from (select a from t3) where rownum <= 10) where row >=5; + a | row +----+----- + 5 | 5 + 6 | 6 + 7 | 7 + 8 | 8 + 9 | 9 + 10 | 10 +(6 rows) + +CREATE TABLE bmsql_item ( +i_id int NoT NULL, +i_name varchar(24), +i_price numeric(5,2), +i_data varchar( 50), +i_im_id int +) with(storage_type=ustore); +insert into bmsql_item values ('1','sqltest_varchar_1','0.01','sqltest_varchar_1','1') ; +insert into bmsql_item values ('2','sqltest_varchar_2','0.02','sqltest_varchar_2','2') ; +insert into bmsql_item values ('3','sqltest_varchar_3','0.03','sqltest_varchar_3','3') ; +insert into bmsql_item values ('4','sqltest_varchar_4','0.04','sqltest_varchar_4','4') ; +insert into bmsql_item(i_id) values ('5'); +create table bmsql_warehouse( +w_id int not null, +w_ytd numeric(12,2), +w_tax numeric(4,4), +w_name varchar(10), +w_street_1 varchar(20), +w_street_2 varchar(20), +w_city varchar(20), +w_state char(2), +w_zip char(9) +) with(storage_type=ustore); +insert into bmsql_warehouse values('1','0.01','0.0001','sqltest_va','sqltest_varchar_1','sqltest_varchar_1','sqltest_varchar_1','sq','sqltest_b'); +insert into bmsql_warehouse values('2','0.02','0.0002','sqltest_va','sqltest_varchar_2','sqltest_varchar_2','sqltest_varchar_2','sq','sqltest_b'); +insert into bmsql_warehouse values('3','0.03','0.0003','sqltest_va','sqltest_varchar_3','sqltest_varchar_3','sqltest_varchar_3','sq','sqltest_b'); +insert into bmsql_warehouse values('4','0.04','0.0004','sqltest_va','sqltest_varchar_4','sqltest_varchar_4','sqltest_varchar_4','sq','sqltest_b'); +insert into bmsql_warehouse(w_id) values('5'); +set query_dop=4; +explain (costs off) select 0.01 +from bmsql_item +intersect +select first_value(i_price) over (order by 2) +from bmsql_item +where i_id <=(select w_id from bmsql_warehouse +where bmsql_item.i_name not like 'sqltest_varchar_2' order by 1 limit 1) +group by i_price; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------- + HashSetOp Intersect + -> Append + -> Subquery Scan on "*SELECT* 1" + -> Seq Scan on bmsql_item + -> Subquery Scan on "*SELECT* 2" + -> WindowAgg + -> Streaming(type: BROADCAST dop: 1/4) + -> Group + Group By Key: test_smp.bmsql_item.i_price + -> Sort + Sort Key: test_smp.bmsql_item.i_price + -> Streaming(type: LOCAL REDISTRIBUTE dop: 4/1) + -> Group + Group By Key: test_smp.bmsql_item.i_price + -> Sort + Sort Key: test_smp.bmsql_item.i_price + -> Seq Scan on bmsql_item + Filter: (i_id <= (SubPlan 1)) + SubPlan 1 + -> Limit + -> Sort + Sort Key: bmsql_warehouse.w_id + -> Result + One-Time Filter: ((test_smp.bmsql_item.i_name)::text !~~ 'sqltest_varchar_2'::text) + -> Seq Scan on bmsql_warehouse +(25 rows) + +select 0.01 +from bmsql_item +intersect +select first_value(i_price) over (order by 2) +from bmsql_item +where i_id <=(select w_id from bmsql_warehouse +where bmsql_item.i_name not like 'sqltest_varchar_2' order by 1 limit 1) +group by i_price; + ?column? +---------- + .01 +(1 row) + +CREATE FUNCTION f1(text) RETURNS int LANGUAGE SQL IMMUTABLE AS $$ SELECT $1::int;$$; +CREATE TABLE bmsql_history ( +hist_id int, +h_c_id int, +h_c_d_id int, +h_c_w_id int, +h_d_id int, +h_w_id int, +h_date timestamp(6), +h_amount numeric(6,2), +h_data varchar( 24) +) with(storage_type=ustore); +insert into bmsql_history values('1','1','1','1','1','1',to_timestamp('2010-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss'),'0.01','sqltest_varchar_1') ; +insert into bmsql_history values('2','2','2','2','2','2',to_timestamp('2010-01-02 00:00:00','yyyy-mm-dd hh24:mi:ss'),'0.02','sqltest_varchar_2') ; +insert into bmsql_history values('3','3','3','3','3','3',to_timestamp('2010-01-03 00:00:00','yyyy-mm-dd hh24:mi:ss'),'0.03','sqltest_varchar_3') ; +insert into bmsql_history values('4','4','4','4','4','4',to_timestamp('2010-01-03 00:00:00','yyyy-mm-dd hh24:mi:ss'),'0.04','sqltest_varchar_4') ; +insert into bmsql_history(hist_id) values('') ; +explain (costs off) select f1('0') c1 +union +select distinct i_id c2 +from bmsql_item +where i_id not like (with tmp as (select distinct asin(0) as c1 from bmsql_history where bmsql_item.i_im_id <3) +select * from tmp); + QUERY PLAN +----------------------------------------------------------------------------------------------- + HashAggregate + Group By Key: (0) + -> Append + -> Result + -> Streaming(type: LOCAL GATHER dop: 1/4) + -> HashAggregate + Group By Key: bmsql_item.i_id + -> Streaming(type: LOCAL REDISTRIBUTE dop: 4/1) + -> HashAggregate + Group By Key: bmsql_item.i_id + -> Seq Scan on bmsql_item + Filter: ((i_id)::text !~~ ((SubPlan 1))::text) + SubPlan 1 + -> Unique + -> Result + One-Time Filter: (bmsql_item.i_im_id < 3) + -> Seq Scan on bmsql_history +(17 rows) + +select f1('0') c1 +union +select distinct i_id c2 +from bmsql_item +where i_id not like (with tmp as (select distinct asin(0) as c1 from bmsql_history where bmsql_item.i_im_id <3) +select * from tmp); + c1 +---- + 1 + 0 + 2 +(3 rows) + +explain (costs off) select distinct i_id c2 +from bmsql_item +where i_id not like (with tmp as (select distinct asin(0) as c1 from bmsql_history where bmsql_item.i_im_id <3) +select * from tmp) +union +select f1('0') c1; + QUERY PLAN +----------------------------------------------------------------------------------------------- + HashAggregate + Group By Key: bmsql_item.i_id + -> Append + -> Streaming(type: LOCAL GATHER dop: 1/4) + -> HashAggregate + Group By Key: bmsql_item.i_id + -> Streaming(type: LOCAL REDISTRIBUTE dop: 4/1) + -> HashAggregate + Group By Key: bmsql_item.i_id + -> Seq Scan on bmsql_item + Filter: ((i_id)::text !~~ ((SubPlan 1))::text) + SubPlan 1 + -> Unique + -> Result + One-Time Filter: (bmsql_item.i_im_id < 3) + -> Seq Scan on bmsql_history + -> Result +(17 rows) + +select distinct i_id c2 +from bmsql_item +where i_id not like (with tmp as (select distinct asin(0) as c1 from bmsql_history where bmsql_item.i_im_id <3) +select * from tmp) +union +select f1('0') c1; + c2 +---- + 1 + 0 + 2 +(3 rows) + +select f1(0) c1 +union +select distinct var_pop(i_id) c2 +from bmsql_item +where i_id not like (with tmp as (select distinct asin(0) as c1 from bmsql_history where bmsql_item.i_im_id <3) +select * from tmp); + c1 +----------------------- + 0 + .25000000000000000000 +(2 rows) + +select distinct var_pop(i_id) c2 +from bmsql_item +where i_id not like (with tmp as (select distinct asin(0) as c1 from bmsql_history where bmsql_item.i_im_id <3) +select * from tmp) +union +select f1(0) c1; + c2 +----------------------- + 0 + .25000000000000000000 +(2 rows) + +CREATE TABLE bmsql_new_order ( +no_w_id int NOT NULL, +no_d_id int NOT NULL, +no_o_id int NOT NULL +) with(storage_type=ustore); +insert into bmsql_new_order values('1','1','1'); +insert into bmsql_new_order values('2','2','2'); +insert into bmsql_new_order values('3','3','3'); +insert into bmsql_new_order values('4','4','4'); +insert into bmsql_new_order values('5','5','5'); +select count(*) +from (select distinct greatest (no_d_id,no_d_id,no_d_id) +from bmsql_new_order +where no_o_id not in ( with tmp as (select w_id from bmsql_warehouse where bmsql_new_order.no_w_id >2 or w_id >=3) select * from tmp)) tb1, +( select count(*) from bmsql_item group by i_im_id,i_im_id having i_im_id like f1('0') +) tb2; + count +------- + 0 +(1 row) + +--clean +reset query_dop; +set search_path=public; +drop schema test_smp cascade; +NOTICE: drop cascades to 8 other objects +DETAIL: drop cascades to table test_smp.t1 +drop cascades to table test_smp.t2 +drop cascades to table test_smp.t3 +drop cascades to table test_smp.bmsql_item +drop cascades to table test_smp.bmsql_warehouse +drop cascades to function test_smp.f1(text) +drop cascades to table test_smp.bmsql_history +drop cascades to table test_smp.bmsql_new_order diff --git a/src/test/regress/sql/smp_seq_scan_ustore.sql b/src/test/regress/sql/smp_seq_scan_ustore.sql new file mode 100644 index 0000000000..222490a3b9 --- /dev/null +++ b/src/test/regress/sql/smp_seq_scan_ustore.sql @@ -0,0 +1,208 @@ +create schema test_smp; +set search_path=test_smp; + +create table t1(a int, b int, c int, d bigint) with(storage_type=ustore); +insert into t1 values(generate_series(1, 100), generate_series(1, 10), generate_series(1, 2), generate_series(1, 50)); +create table t2(a int, b int) with(storage_type=ustore); +insert into t2 values(generate_series(1, 10), generate_series(1, 30)); +create table t3(a int, b int, c int) with(storage_type=ustore); +insert into t3 values(generate_series(1, 50), generate_series(1, 100), generate_series(1, 10)); + +analyze t1; +analyze t2; +analyze t3; + +set query_dop=1002; +explain (costs off) select * from t2 order by 1,2; +select * from t2 order by 1,2; + +set enable_nestloop=on; +set enable_mergejoin=off; +set enable_hashjoin=off; +explain (costs off) select t1.a,t2.b from t1, t2 where t1.a = t2.a order by 1,2; +select t1.a,t2.b from t1, t2 where t1.a = t2.a order by 1,2; + +set enable_nestloop=off; +set enable_hashjoin=on; +explain (costs off) select t1.a,t2.b,t3.c from t1, t2, t3 where t1.a = t2.a and t1.b = t3.c order by 1,2,3; +select t1.a,t2.b,t3.c from t1, t2, t3 where t1.a = t2.a and t1.b = t3.c order by 1,2,3; + +set enable_nestloop=on; +explain (costs off) select a, avg(b), sum(c) from t1 group by a order by 1,2,3; +select a, avg(b), sum(c) from t1 group by a order by 1,2,3; + +explain (costs off) select median(a) from t1; +select median(a) from t1; + +explain (costs off) select first(a) from t1; +select first(a) from t1; + +explain (costs off) select sum(b)+median(a) as result from t1; +select sum(b)+median(a) as result from t1; + +explain (costs off) select a, count(distinct b) from t1 group by a order by 1 limit 10; +select a, count(distinct b) from t1 group by a order by 1 limit 10; + +explain (costs off) select count(distinct b), count(distinct c) from t1 limit 10; +select count(distinct b), count(distinct c) from t1 limit 10; + +explain (costs off) select distinct b from t1 union all select distinct a from t2 order by 1; +select distinct b from t1 union all select distinct a from t2 order by 1; + +explain (costs off) select * from t1 where t1.a in (select t2.a from t2, t3 where t2.b = t3.c) order by 1,2,3; +select * from t1 where t1.a in (select t2.a from t2, t3 where t2.b = t3.c) order by 1,2,3; + +explain (costs off) with s1 as (select t1.a as a, t3.b as b from t1,t3 where t1.b=t3.c) select * from t2, s1 where t2.b=s1.a order by 1,2,3,4; +with s1 as (select t1.a as a, t3.b as b from t1,t3 where t1.b=t3.c) select * from t2, s1 where t2.b=s1.a order by 1,2,3,4; + +explain (costs off) select * from t1 order by a limit 10; +select * from t1 order by a limit 10; + +explain (costs off) select * from t1 order by a limit 10 offset 20; +select * from t1 order by a limit 10 offset 20; + +-- test limit and offset +explain (costs off) select * from t1 limit 1; + +explain (costs off) select * from t1 limit 1 offset 10; + +explain (costs off) select * from t1 order by 1 limit 1 offset 10; + +-- test subquery recursive +explain (costs off) select * from (select a, rownum as row from (select a from t3) where rownum <= 10) where row >=5; +select * from (select a, rownum as row from (select a from t3) where rownum <= 10) where row >=5; + +CREATE TABLE bmsql_item ( +i_id int NoT NULL, +i_name varchar(24), +i_price numeric(5,2), +i_data varchar( 50), +i_im_id int +) with(storage_type=ustore); +insert into bmsql_item values ('1','sqltest_varchar_1','0.01','sqltest_varchar_1','1') ; +insert into bmsql_item values ('2','sqltest_varchar_2','0.02','sqltest_varchar_2','2') ; +insert into bmsql_item values ('3','sqltest_varchar_3','0.03','sqltest_varchar_3','3') ; +insert into bmsql_item values ('4','sqltest_varchar_4','0.04','sqltest_varchar_4','4') ; +insert into bmsql_item(i_id) values ('5'); + +create table bmsql_warehouse( +w_id int not null, +w_ytd numeric(12,2), +w_tax numeric(4,4), +w_name varchar(10), +w_street_1 varchar(20), +w_street_2 varchar(20), +w_city varchar(20), +w_state char(2), +w_zip char(9) +) with(storage_type=ustore); +insert into bmsql_warehouse values('1','0.01','0.0001','sqltest_va','sqltest_varchar_1','sqltest_varchar_1','sqltest_varchar_1','sq','sqltest_b'); +insert into bmsql_warehouse values('2','0.02','0.0002','sqltest_va','sqltest_varchar_2','sqltest_varchar_2','sqltest_varchar_2','sq','sqltest_b'); +insert into bmsql_warehouse values('3','0.03','0.0003','sqltest_va','sqltest_varchar_3','sqltest_varchar_3','sqltest_varchar_3','sq','sqltest_b'); +insert into bmsql_warehouse values('4','0.04','0.0004','sqltest_va','sqltest_varchar_4','sqltest_varchar_4','sqltest_varchar_4','sq','sqltest_b'); +insert into bmsql_warehouse(w_id) values('5'); + +set query_dop=4; + +explain (costs off) select 0.01 +from bmsql_item +intersect +select first_value(i_price) over (order by 2) +from bmsql_item +where i_id <=(select w_id from bmsql_warehouse +where bmsql_item.i_name not like 'sqltest_varchar_2' order by 1 limit 1) +group by i_price; + +select 0.01 +from bmsql_item +intersect +select first_value(i_price) over (order by 2) +from bmsql_item +where i_id <=(select w_id from bmsql_warehouse +where bmsql_item.i_name not like 'sqltest_varchar_2' order by 1 limit 1) +group by i_price; + +CREATE FUNCTION f1(text) RETURNS int LANGUAGE SQL IMMUTABLE AS $$ SELECT $1::int;$$; + +CREATE TABLE bmsql_history ( +hist_id int, +h_c_id int, +h_c_d_id int, +h_c_w_id int, +h_d_id int, +h_w_id int, +h_date timestamp(6), +h_amount numeric(6,2), +h_data varchar( 24) +) with(storage_type=ustore); + +insert into bmsql_history values('1','1','1','1','1','1',to_timestamp('2010-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss'),'0.01','sqltest_varchar_1') ; +insert into bmsql_history values('2','2','2','2','2','2',to_timestamp('2010-01-02 00:00:00','yyyy-mm-dd hh24:mi:ss'),'0.02','sqltest_varchar_2') ; +insert into bmsql_history values('3','3','3','3','3','3',to_timestamp('2010-01-03 00:00:00','yyyy-mm-dd hh24:mi:ss'),'0.03','sqltest_varchar_3') ; +insert into bmsql_history values('4','4','4','4','4','4',to_timestamp('2010-01-03 00:00:00','yyyy-mm-dd hh24:mi:ss'),'0.04','sqltest_varchar_4') ; +insert into bmsql_history(hist_id) values('') ; + +explain (costs off) select f1('0') c1 +union +select distinct i_id c2 +from bmsql_item +where i_id not like (with tmp as (select distinct asin(0) as c1 from bmsql_history where bmsql_item.i_im_id <3) +select * from tmp); + +select f1('0') c1 +union +select distinct i_id c2 +from bmsql_item +where i_id not like (with tmp as (select distinct asin(0) as c1 from bmsql_history where bmsql_item.i_im_id <3) +select * from tmp); + +explain (costs off) select distinct i_id c2 +from bmsql_item +where i_id not like (with tmp as (select distinct asin(0) as c1 from bmsql_history where bmsql_item.i_im_id <3) +select * from tmp) +union +select f1('0') c1; + +select distinct i_id c2 +from bmsql_item +where i_id not like (with tmp as (select distinct asin(0) as c1 from bmsql_history where bmsql_item.i_im_id <3) +select * from tmp) +union +select f1('0') c1; + +select f1(0) c1 +union +select distinct var_pop(i_id) c2 +from bmsql_item +where i_id not like (with tmp as (select distinct asin(0) as c1 from bmsql_history where bmsql_item.i_im_id <3) +select * from tmp); + +select distinct var_pop(i_id) c2 +from bmsql_item +where i_id not like (with tmp as (select distinct asin(0) as c1 from bmsql_history where bmsql_item.i_im_id <3) +select * from tmp) +union +select f1(0) c1; + +CREATE TABLE bmsql_new_order ( +no_w_id int NOT NULL, +no_d_id int NOT NULL, +no_o_id int NOT NULL +) with(storage_type=ustore); +insert into bmsql_new_order values('1','1','1'); +insert into bmsql_new_order values('2','2','2'); +insert into bmsql_new_order values('3','3','3'); +insert into bmsql_new_order values('4','4','4'); +insert into bmsql_new_order values('5','5','5'); + +select count(*) +from (select distinct greatest (no_d_id,no_d_id,no_d_id) +from bmsql_new_order +where no_o_id not in ( with tmp as (select w_id from bmsql_warehouse where bmsql_new_order.no_w_id >2 or w_id >=3) select * from tmp)) tb1, +( select count(*) from bmsql_item group by i_im_id,i_im_id having i_im_id like f1('0') +) tb2; + +--clean +reset query_dop; +set search_path=public; +drop schema test_smp cascade; -- Gitee