提交 8f5f09d8 编写于 作者: H Heikki Linnakangas

Move tests for static partition selection from TINC.

I moved them to the 'partition_pruning_with_fn' test, but because there is
no functions involved in these tests, I renamed the test to just
'partition_pruning'.

There is possibly some overlap with these new tests and the existing ones
in the same file, but will let future test archeologists to decide that.
These are cheap tests, in any case.
上级 ce4f96b8
......@@ -317,3 +317,306 @@ select * from mytable where ZeroFunc(i)=0 and i=-1 order by i;
drop function ZeroFunc(int) cascade;
NOTICE: drop cascades to index mytable_idx1
drop table mytable cascade;
-- start_ignore
create language plpythonu;
-- end_ignore
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
create or replace function get_selected_parts(explain_query text) returns text as
$$
rv = plpy.execute('explain ' + explain_query)
search_text = 'Partition Selector'
result = []
result.append(0)
result.append(0)
for i in range(len(rv)):
cur_line = rv[i]['QUERY PLAN']
if search_text.lower() in cur_line.lower():
j = i+1
temp_line = rv[j]['QUERY PLAN']
while temp_line.find('Partitions selected:') == -1:
j += 1
if j == len(rv) - 1:
break
temp_line = rv[j]['QUERY PLAN']
if temp_line.find('Partitions selected:') != -1:
result[0] = int(temp_line[temp_line.index('selected: ')+10:temp_line.index(' (out')])
result[1] = int(temp_line[temp_line.index('out of')+6:temp_line.index(')')])
return result
$$
language plpythonu;
drop table if exists partprune_foo;
create table partprune_foo(a int, b int, c int) partition by range (b) (start (1) end (101) every (10));
insert into partprune_foo select generate_series(1,5), generate_series(1,100), generate_series(1,10);
analyze partprune_foo;
select get_selected_parts(' select * from partprune_foo;');
get_selected_parts
--------------------
[0, 0]
(1 row)
select * from partprune_foo;
a | b | c
---+-----+----
1 | 1 | 1
3 | 3 | 3
5 | 5 | 5
1 | 6 | 6
3 | 8 | 8
5 | 10 | 10
1 | 11 | 1
3 | 13 | 3
5 | 15 | 5
1 | 16 | 6
3 | 18 | 8
5 | 20 | 10
1 | 21 | 1
3 | 23 | 3
5 | 25 | 5
1 | 26 | 6
3 | 28 | 8
5 | 30 | 10
1 | 31 | 1
3 | 33 | 3
5 | 35 | 5
1 | 36 | 6
3 | 38 | 8
5 | 40 | 10
1 | 41 | 1
3 | 43 | 3
5 | 45 | 5
1 | 46 | 6
3 | 48 | 8
5 | 50 | 10
1 | 51 | 1
3 | 53 | 3
5 | 55 | 5
1 | 56 | 6
3 | 58 | 8
5 | 60 | 10
1 | 61 | 1
3 | 63 | 3
5 | 65 | 5
1 | 66 | 6
3 | 68 | 8
5 | 70 | 10
1 | 71 | 1
3 | 73 | 3
5 | 75 | 5
1 | 76 | 6
3 | 78 | 8
5 | 80 | 10
1 | 81 | 1
3 | 83 | 3
5 | 85 | 5
1 | 86 | 6
3 | 88 | 8
5 | 90 | 10
1 | 91 | 1
3 | 93 | 3
5 | 95 | 5
1 | 96 | 6
3 | 98 | 8
5 | 100 | 10
2 | 2 | 2
4 | 4 | 4
2 | 7 | 7
4 | 9 | 9
2 | 12 | 2
4 | 14 | 4
2 | 17 | 7
4 | 19 | 9
2 | 22 | 2
4 | 24 | 4
2 | 27 | 7
4 | 29 | 9
2 | 32 | 2
4 | 34 | 4
2 | 37 | 7
4 | 39 | 9
2 | 42 | 2
4 | 44 | 4
2 | 47 | 7
4 | 49 | 9
2 | 52 | 2
4 | 54 | 4
2 | 57 | 7
4 | 59 | 9
2 | 62 | 2
4 | 64 | 4
2 | 67 | 7
4 | 69 | 9
2 | 72 | 2
4 | 74 | 4
2 | 77 | 7
4 | 79 | 9
2 | 82 | 2
4 | 84 | 4
2 | 87 | 7
4 | 89 | 9
2 | 92 | 2
4 | 94 | 4
2 | 97 | 7
4 | 99 | 9
(100 rows)
select get_selected_parts(' select * from partprune_foo where b = 35;');
get_selected_parts
--------------------
[0, 0]
(1 row)
select * from partprune_foo where b = 35;
a | b | c
---+----+---
5 | 35 | 5
(1 row)
select get_selected_parts(' select * from partprune_foo where b < 35;');
get_selected_parts
--------------------
[0, 0]
(1 row)
select * from partprune_foo where b < 35;
a | b | c
---+----+----
2 | 2 | 2
4 | 4 | 4
2 | 7 | 7
4 | 9 | 9
2 | 12 | 2
4 | 14 | 4
2 | 17 | 7
4 | 19 | 9
2 | 22 | 2
4 | 24 | 4
2 | 27 | 7
4 | 29 | 9
2 | 32 | 2
4 | 34 | 4
1 | 1 | 1
3 | 3 | 3
5 | 5 | 5
1 | 6 | 6
3 | 8 | 8
5 | 10 | 10
1 | 11 | 1
3 | 13 | 3
5 | 15 | 5
1 | 16 | 6
3 | 18 | 8
5 | 20 | 10
1 | 21 | 1
3 | 23 | 3
5 | 25 | 5
1 | 26 | 6
3 | 28 | 8
5 | 30 | 10
1 | 31 | 1
3 | 33 | 3
(34 rows)
select get_selected_parts(' select * from partprune_foo where b in (5, 6, 14, 23);');
get_selected_parts
--------------------
[0, 0]
(1 row)
select * from partprune_foo where b in (5, 6, 14, 23);
a | b | c
---+----+---
5 | 5 | 5
1 | 6 | 6
3 | 23 | 3
4 | 14 | 4
(4 rows)
select get_selected_parts(' select * from partprune_foo where b < 15 or b > 60;');
get_selected_parts
--------------------
[0, 0]
(1 row)
select * from partprune_foo where b < 15 or b > 60;
a | b | c
---+-----+----
2 | 2 | 2
4 | 4 | 4
2 | 7 | 7
4 | 9 | 9
2 | 12 | 2
4 | 14 | 4
2 | 62 | 2
4 | 64 | 4
2 | 67 | 7
4 | 69 | 9
2 | 72 | 2
4 | 74 | 4
2 | 77 | 7
4 | 79 | 9
2 | 82 | 2
4 | 84 | 4
2 | 87 | 7
4 | 89 | 9
2 | 92 | 2
4 | 94 | 4
2 | 97 | 7
4 | 99 | 9
1 | 1 | 1
3 | 3 | 3
5 | 5 | 5
1 | 6 | 6
3 | 8 | 8
5 | 10 | 10
1 | 11 | 1
3 | 13 | 3
1 | 61 | 1
3 | 63 | 3
5 | 65 | 5
1 | 66 | 6
3 | 68 | 8
5 | 70 | 10
1 | 71 | 1
3 | 73 | 3
5 | 75 | 5
1 | 76 | 6
3 | 78 | 8
5 | 80 | 10
1 | 81 | 1
3 | 83 | 3
5 | 85 | 5
1 | 86 | 6
3 | 88 | 8
5 | 90 | 10
1 | 91 | 1
3 | 93 | 3
5 | 95 | 5
1 | 96 | 6
3 | 98 | 8
5 | 100 | 10
(54 rows)
select get_selected_parts(' select * from partprune_foo where b = 150;');
get_selected_parts
--------------------
[0, 0]
(1 row)
select * from partprune_foo where b = 150;
a | b | c
---+---+---
(0 rows)
select get_selected_parts(' select * from partprune_foo where b = a*5;');
get_selected_parts
--------------------
[0, 0]
(1 row)
select * from partprune_foo where b = a*5;
a | b | c
---+----+---
5 | 25 | 5
(1 row)
......@@ -360,3 +360,303 @@ select * from mytable where ZeroFunc(i)=0 and i=-1 order by i;
drop function ZeroFunc(int) cascade;
NOTICE: drop cascades to index mytable_idx1
drop table mytable cascade;
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
create or replace function get_selected_parts(explain_query text) returns text as
$$
rv = plpy.execute('explain ' + explain_query)
search_text = 'Partition Selector'
result = []
result.append(0)
result.append(0)
for i in range(len(rv)):
cur_line = rv[i]['QUERY PLAN']
if search_text.lower() in cur_line.lower():
j = i+1
temp_line = rv[j]['QUERY PLAN']
while temp_line.find('Partitions selected:') == -1:
j += 1
if j == len(rv) - 1:
break
temp_line = rv[j]['QUERY PLAN']
if temp_line.find('Partitions selected:') != -1:
result[0] = int(temp_line[temp_line.index('selected: ')+10:temp_line.index(' (out')])
result[1] = int(temp_line[temp_line.index('out of')+6:temp_line.index(')')])
return result
$$
language plpythonu;
drop table if exists partprune_foo;
create table partprune_foo(a int, b int, c int) partition by range (b) (start (1) end (101) every (10));
insert into partprune_foo select generate_series(1,5), generate_series(1,100), generate_series(1,10);
analyze partprune_foo;
select get_selected_parts('select * from partprune_foo;');
get_selected_parts
--------------------
[10, 10]
(1 row)
select * from partprune_foo;
a | b | c
---+-----+----
1 | 1 | 1
3 | 3 | 3
5 | 5 | 5
1 | 6 | 6
3 | 8 | 8
5 | 10 | 10
1 | 11 | 1
3 | 13 | 3
5 | 15 | 5
1 | 16 | 6
3 | 18 | 8
5 | 20 | 10
1 | 21 | 1
3 | 23 | 3
5 | 25 | 5
1 | 26 | 6
3 | 28 | 8
5 | 30 | 10
1 | 31 | 1
3 | 33 | 3
5 | 35 | 5
1 | 36 | 6
3 | 38 | 8
5 | 40 | 10
1 | 41 | 1
3 | 43 | 3
5 | 45 | 5
1 | 46 | 6
3 | 48 | 8
5 | 50 | 10
1 | 51 | 1
3 | 53 | 3
5 | 55 | 5
1 | 56 | 6
3 | 58 | 8
5 | 60 | 10
1 | 61 | 1
3 | 63 | 3
5 | 65 | 5
1 | 66 | 6
3 | 68 | 8
5 | 70 | 10
1 | 71 | 1
3 | 73 | 3
5 | 75 | 5
1 | 76 | 6
3 | 78 | 8
5 | 80 | 10
1 | 81 | 1
3 | 83 | 3
5 | 85 | 5
1 | 86 | 6
3 | 88 | 8
5 | 90 | 10
1 | 91 | 1
3 | 93 | 3
5 | 95 | 5
1 | 96 | 6
3 | 98 | 8
5 | 100 | 10
2 | 2 | 2
4 | 4 | 4
2 | 7 | 7
4 | 9 | 9
2 | 12 | 2
4 | 14 | 4
2 | 17 | 7
4 | 19 | 9
2 | 22 | 2
4 | 24 | 4
2 | 27 | 7
4 | 29 | 9
2 | 32 | 2
4 | 34 | 4
2 | 37 | 7
4 | 39 | 9
2 | 42 | 2
4 | 44 | 4
2 | 47 | 7
4 | 49 | 9
2 | 52 | 2
4 | 54 | 4
2 | 57 | 7
4 | 59 | 9
2 | 62 | 2
4 | 64 | 4
2 | 67 | 7
4 | 69 | 9
2 | 72 | 2
4 | 74 | 4
2 | 77 | 7
4 | 79 | 9
2 | 82 | 2
4 | 84 | 4
2 | 87 | 7
4 | 89 | 9
2 | 92 | 2
4 | 94 | 4
2 | 97 | 7
4 | 99 | 9
(100 rows)
select get_selected_parts('select * from partprune_foo where b = 35;');
get_selected_parts
--------------------
[1, 10]
(1 row)
select * from partprune_foo where b = 35;
a | b | c
---+----+---
5 | 35 | 5
(1 row)
select get_selected_parts('select * from partprune_foo where b < 35;');
get_selected_parts
--------------------
[4, 10]
(1 row)
select * from partprune_foo where b < 35;
a | b | c
---+----+----
2 | 2 | 2
4 | 4 | 4
2 | 7 | 7
4 | 9 | 9
2 | 12 | 2
4 | 14 | 4
2 | 17 | 7
4 | 19 | 9
2 | 22 | 2
4 | 24 | 4
2 | 27 | 7
4 | 29 | 9
2 | 32 | 2
4 | 34 | 4
1 | 1 | 1
3 | 3 | 3
5 | 5 | 5
1 | 6 | 6
3 | 8 | 8
5 | 10 | 10
1 | 11 | 1
3 | 13 | 3
5 | 15 | 5
1 | 16 | 6
3 | 18 | 8
5 | 20 | 10
1 | 21 | 1
3 | 23 | 3
5 | 25 | 5
1 | 26 | 6
3 | 28 | 8
5 | 30 | 10
1 | 31 | 1
3 | 33 | 3
(34 rows)
select get_selected_parts('select * from partprune_foo where b in (5, 6, 14, 23);');
get_selected_parts
--------------------
[3, 10]
(1 row)
select * from partprune_foo where b in (5, 6, 14, 23);
a | b | c
---+----+---
5 | 5 | 5
1 | 6 | 6
3 | 23 | 3
4 | 14 | 4
(4 rows)
select get_selected_parts('select * from partprune_foo where b < 15 or b > 60;');
get_selected_parts
--------------------
[7, 10]
(1 row)
select * from partprune_foo where b < 15 or b > 60;
a | b | c
---+-----+----
2 | 2 | 2
4 | 4 | 4
2 | 7 | 7
4 | 9 | 9
2 | 12 | 2
4 | 14 | 4
2 | 62 | 2
4 | 64 | 4
2 | 67 | 7
4 | 69 | 9
2 | 72 | 2
4 | 74 | 4
2 | 77 | 7
4 | 79 | 9
2 | 82 | 2
4 | 84 | 4
2 | 87 | 7
4 | 89 | 9
2 | 92 | 2
4 | 94 | 4
2 | 97 | 7
4 | 99 | 9
1 | 1 | 1
3 | 3 | 3
5 | 5 | 5
1 | 6 | 6
3 | 8 | 8
5 | 10 | 10
1 | 11 | 1
3 | 13 | 3
1 | 61 | 1
3 | 63 | 3
5 | 65 | 5
1 | 66 | 6
3 | 68 | 8
5 | 70 | 10
1 | 71 | 1
3 | 73 | 3
5 | 75 | 5
1 | 76 | 6
3 | 78 | 8
5 | 80 | 10
1 | 81 | 1
3 | 83 | 3
5 | 85 | 5
1 | 86 | 6
3 | 88 | 8
5 | 90 | 10
1 | 91 | 1
3 | 93 | 3
5 | 95 | 5
1 | 96 | 6
3 | 98 | 8
5 | 100 | 10
(54 rows)
select get_selected_parts('select * from partprune_foo where b = 150;');
get_selected_parts
--------------------
[0, 10]
(1 row)
select * from partprune_foo where b = 150;
a | b | c
---+---+---
(0 rows)
select get_selected_parts('select * from partprune_foo where b = a*5;');
get_selected_parts
--------------------
[10, 10]
(1 row)
select * from partprune_foo where b = a*5;
a | b | c
---+----+---
5 | 25 | 5
(1 row)
......@@ -87,7 +87,7 @@ test: wrkloadadmin
# vacuum from removing dead tuples.
test: gp_toolkit
test: gp_toolkit_ao_funcs filespace trig auth_constraint role portals_updatable plpgsql_cache timeseries pg_stat_last_operation gp_numeric_agg partindex_test partition_pruning_with_fn runtime_stats
test: gp_toolkit_ao_funcs filespace trig auth_constraint role portals_updatable plpgsql_cache timeseries pg_stat_last_operation gp_numeric_agg partindex_test partition_pruning runtime_stats
test: rle rle_delta dsp
# direct dispatch tests
......
......@@ -225,3 +225,62 @@ select * from mytable where ZeroFunc(i)=0 and i=-1 order by i;
-- cleanup
drop function ZeroFunc(int) cascade;
drop table mytable cascade;
-- start_ignore
create language plpythonu;
-- end_ignore
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
create or replace function get_selected_parts(explain_query text) returns text as
$$
rv = plpy.execute('explain ' + explain_query)
search_text = 'Partition Selector'
result = []
result.append(0)
result.append(0)
for i in range(len(rv)):
cur_line = rv[i]['QUERY PLAN']
if search_text.lower() in cur_line.lower():
j = i+1
temp_line = rv[j]['QUERY PLAN']
while temp_line.find('Partitions selected:') == -1:
j += 1
if j == len(rv) - 1:
break
temp_line = rv[j]['QUERY PLAN']
if temp_line.find('Partitions selected:') != -1:
result[0] = int(temp_line[temp_line.index('selected: ')+10:temp_line.index(' (out')])
result[1] = int(temp_line[temp_line.index('out of')+6:temp_line.index(')')])
return result
$$
language plpythonu;
drop table if exists partprune_foo;
create table partprune_foo(a int, b int, c int) partition by range (b) (start (1) end (101) every (10));
insert into partprune_foo select generate_series(1,5), generate_series(1,100), generate_series(1,10);
analyze partprune_foo;
select get_selected_parts(' select * from partprune_foo;');
select * from partprune_foo;
select get_selected_parts(' select * from partprune_foo where b = 35;');
select * from partprune_foo where b = 35;
select get_selected_parts(' select * from partprune_foo where b < 35;');
select * from partprune_foo where b < 35;
select get_selected_parts(' select * from partprune_foo where b in (5, 6, 14, 23);');
select * from partprune_foo where b in (5, 6, 14, 23);
select get_selected_parts(' select * from partprune_foo where b < 15 or b > 60;');
select * from partprune_foo where b < 15 or b > 60;
select get_selected_parts(' select * from partprune_foo where b = 150;');
select * from partprune_foo where b = 150;
select get_selected_parts(' select * from partprune_foo where b = a*5;');
select * from partprune_foo where b = a*5;
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo;');
get_selected_parts
--------------------
[10, 10]
(1 row)
select * from foo;
a | b | c
---+-----+----
1 | 1 | 1
3 | 3 | 3
5 | 5 | 5
1 | 6 | 6
3 | 8 | 8
5 | 10 | 10
1 | 11 | 1
3 | 13 | 3
5 | 15 | 5
1 | 16 | 6
3 | 18 | 8
5 | 20 | 10
1 | 21 | 1
3 | 23 | 3
5 | 25 | 5
1 | 26 | 6
3 | 28 | 8
5 | 30 | 10
1 | 31 | 1
3 | 33 | 3
5 | 35 | 5
1 | 36 | 6
3 | 38 | 8
5 | 40 | 10
1 | 41 | 1
3 | 43 | 3
5 | 45 | 5
1 | 46 | 6
3 | 48 | 8
5 | 50 | 10
1 | 51 | 1
3 | 53 | 3
5 | 55 | 5
1 | 56 | 6
3 | 58 | 8
5 | 60 | 10
1 | 61 | 1
3 | 63 | 3
5 | 65 | 5
1 | 66 | 6
3 | 68 | 8
5 | 70 | 10
1 | 71 | 1
3 | 73 | 3
5 | 75 | 5
1 | 76 | 6
3 | 78 | 8
5 | 80 | 10
1 | 81 | 1
3 | 83 | 3
5 | 85 | 5
1 | 86 | 6
3 | 88 | 8
5 | 90 | 10
1 | 91 | 1
3 | 93 | 3
5 | 95 | 5
1 | 96 | 6
3 | 98 | 8
5 | 100 | 10
2 | 2 | 2
4 | 4 | 4
2 | 7 | 7
4 | 9 | 9
2 | 12 | 2
4 | 14 | 4
2 | 17 | 7
4 | 19 | 9
2 | 22 | 2
4 | 24 | 4
2 | 27 | 7
4 | 29 | 9
2 | 32 | 2
4 | 34 | 4
2 | 37 | 7
4 | 39 | 9
2 | 42 | 2
4 | 44 | 4
2 | 47 | 7
4 | 49 | 9
2 | 52 | 2
4 | 54 | 4
2 | 57 | 7
4 | 59 | 9
2 | 62 | 2
4 | 64 | 4
2 | 67 | 7
4 | 69 | 9
2 | 72 | 2
4 | 74 | 4
2 | 77 | 7
4 | 79 | 9
2 | 82 | 2
4 | 84 | 4
2 | 87 | 7
4 | 89 | 9
2 | 92 | 2
4 | 94 | 4
2 | 97 | 7
4 | 99 | 9
(100 rows)
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo where b = 35;');
get_selected_parts
--------------------
[1, 10]
(1 row)
select * from foo where b = 35;
a | b | c
---+----+---
5 | 35 | 5
(1 row)
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo where b < 35;');
get_selected_parts
--------------------
[4, 10]
(1 row)
select * from foo where b < 35;
a | b | c
---+----+----
2 | 2 | 2
4 | 4 | 4
2 | 7 | 7
4 | 9 | 9
2 | 12 | 2
4 | 14 | 4
2 | 17 | 7
4 | 19 | 9
2 | 22 | 2
4 | 24 | 4
2 | 27 | 7
4 | 29 | 9
2 | 32 | 2
4 | 34 | 4
1 | 1 | 1
3 | 3 | 3
5 | 5 | 5
1 | 6 | 6
3 | 8 | 8
5 | 10 | 10
1 | 11 | 1
3 | 13 | 3
5 | 15 | 5
1 | 16 | 6
3 | 18 | 8
5 | 20 | 10
1 | 21 | 1
3 | 23 | 3
5 | 25 | 5
1 | 26 | 6
3 | 28 | 8
5 | 30 | 10
1 | 31 | 1
3 | 33 | 3
(34 rows)
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo where b in (5, 6, 14, 23);');
get_selected_parts
--------------------
[3, 10]
(1 row)
select * from foo where b in (5, 6, 14, 23);
a | b | c
---+----+---
5 | 5 | 5
1 | 6 | 6
3 | 23 | 3
4 | 14 | 4
(4 rows)
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo where b < 15 or b > 60;');
get_selected_parts
--------------------
[7, 10]
(1 row)
select * from foo where b < 15 or b > 60;
a | b | c
---+-----+----
2 | 2 | 2
4 | 4 | 4
2 | 7 | 7
4 | 9 | 9
2 | 12 | 2
4 | 14 | 4
2 | 62 | 2
4 | 64 | 4
2 | 67 | 7
4 | 69 | 9
2 | 72 | 2
4 | 74 | 4
2 | 77 | 7
4 | 79 | 9
2 | 82 | 2
4 | 84 | 4
2 | 87 | 7
4 | 89 | 9
2 | 92 | 2
4 | 94 | 4
2 | 97 | 7
4 | 99 | 9
1 | 1 | 1
3 | 3 | 3
5 | 5 | 5
1 | 6 | 6
3 | 8 | 8
5 | 10 | 10
1 | 11 | 1
3 | 13 | 3
1 | 61 | 1
3 | 63 | 3
5 | 65 | 5
1 | 66 | 6
3 | 68 | 8
5 | 70 | 10
1 | 71 | 1
3 | 73 | 3
5 | 75 | 5
1 | 76 | 6
3 | 78 | 8
5 | 80 | 10
1 | 81 | 1
3 | 83 | 3
5 | 85 | 5
1 | 86 | 6
3 | 88 | 8
5 | 90 | 10
1 | 91 | 1
3 | 93 | 3
5 | 95 | 5
1 | 96 | 6
3 | 98 | 8
5 | 100 | 10
(54 rows)
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo where b = 150;');
get_selected_parts
--------------------
[0, 10]
(1 row)
select * from foo where b = 150;
a | b | c
---+---+---
(0 rows)
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo where b = a*5;');
get_selected_parts
--------------------
[10, 10]
(1 row)
select * from foo where b = a*5;
a | b | c
---+----+---
5 | 25 | 5
(1 row)
create language plpythonu;
create or replace function get_selected_parts(explain_query text) returns text as
$$
rv = plpy.execute(explain_query)
search_text = 'Partition Selector'
result = []
result.append(0)
result.append(0)
for i in range(len(rv)):
cur_line = rv[i]['QUERY PLAN']
if search_text.lower() in cur_line.lower():
j = i+1
temp_line = rv[j]['QUERY PLAN']
while temp_line.find('Partitions selected:') == -1:
j += 1
if j == len(rv) - 1:
break
temp_line = rv[j]['QUERY PLAN']
if temp_line.find('Partitions selected:') != -1:
result[0] = int(temp_line[temp_line.index('selected: ')+10:temp_line.index(' (out')])
result[1] = int(temp_line[temp_line.index('out of')+6:temp_line.index(')')])
return result
$$
language plpythonu;
drop table if exists foo;
create table foo(a int, b int, c int) partition by range (b) (start (1) end (101) every (10));
insert into foo select generate_series(1,5), generate_series(1,100), generate_series(1,10);
analyze foo;
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo;');
select * from foo;
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo where b = 35;');
select * from foo where b = 35;
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo where b < 35;');
select * from foo where b < 35;
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo where b in (5, 6, 14, 23);');
select * from foo where b in (5, 6, 14, 23);
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo where b < 15 or b > 60;');
select * from foo where b < 15 or b > 60;
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo where b = 150;');
select * from foo where b = 150;
-- @author elhela
-- @created 2014-10-14 12:00:00
-- @modified 2014-10-14 12:00:00
-- @description Tests for static partition selection (MPP-24709, GPSQL-2879)
-- @tags MPP-24709 GPSQL-2879 ORCA HAWQ
-- @product_version gpdb: [4.3.3.0-], hawq: [1.2.2.0-]
-- @optimizer_mode on
-- @gpopt 1.499
select get_selected_parts('explain select * from foo where b = a*5;');
select * from foo where b = a*5;
from mpp.models import SQLTestCase
class test_static_selection(SQLTestCase):
'''
Includes testing for static partition selection (MPP-24709, GPSQL-2879)
'''
sql_dir = 'sql/'
ans_dir = 'expected/'
out_dir = 'output/'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册