Skip to content

Commit 6280d4e

Browse files
committed
improve regression tests for RuntimeAppend
1 parent 845d7c8 commit 6280d4e

File tree

4 files changed

+60
-40
lines changed

4 files changed

+60
-40
lines changed

expected/pathman_runtime_nodes.out

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ select pathman.create_hash_partitions('test.runtime_test_3', 'id', 4);
260260

261261
create index on test.runtime_test_3 (id);
262262
create index on test.runtime_test_3_0 (id);
263+
create table test.runtime_test_4(val text, id int not null);
264+
insert into test.runtime_test_4(id, val) select * from generate_series(1, 10000) k, md5(k::text);
265+
select pathman.create_range_partitions('test.runtime_test_4', 'id', 1, 2000);
266+
NOTICE: sequence "runtime_test_4_seq" does not exist, skipping
267+
create_range_partitions
268+
-------------------------
269+
5
270+
(1 row)
271+
263272
VACUUM ANALYZE;
264273
set pg_pathman.enable_runtimeappend = on;
265274
set pg_pathman.enable_runtimemergeappend = on;
@@ -293,19 +302,6 @@ select test.pathman_test_5(); /* projection tests for RuntimeXXX nodes */
293302
ok
294303
(1 row)
295304

296-
/* RuntimeAppend (select ... where id = ANY (subquery), missing partitions) */
297-
select count(*) = 0 from pathman.pathman_partition_list
298-
where parent = 'test.runtime_test_1'::regclass and range_max::int < 0;
299-
?column?
300-
----------
301-
t
302-
(1 row)
303-
304-
select from test.runtime_test_1
305-
where id = any (select generate_series(-10, -1)); /* should be empty */
306-
--
307-
(0 rows)
308-
309305
/* RuntimeAppend (join, enabled parent) */
310306
select pathman.set_enable_parent('test.runtime_test_1', true);
311307
set_enable_parent
@@ -393,7 +389,24 @@ join (select * from test.run_values limit 4) as t2 on t1.id = t2.val;
393389
2
394390
(8 rows)
395391

392+
/* RuntimeAppend (select ... where id = ANY (subquery), missing partitions) */
393+
select count(*) = 0 from pathman.pathman_partition_list
394+
where parent = 'test.runtime_test_4'::regclass and coalesce(range_min::int, 1) < 0;
395+
?column?
396+
----------
397+
t
398+
(1 row)
399+
400+
set enable_hashjoin = off;
401+
set enable_mergejoin = off;
402+
select from test.runtime_test_4
403+
where id = any (select generate_series(-10, -1)); /* should be empty */
404+
--
405+
(0 rows)
406+
407+
set enable_hashjoin = on;
408+
set enable_mergejoin = on;
396409
DROP SCHEMA test CASCADE;
397-
NOTICE: drop cascades to 30 other objects
410+
NOTICE: drop cascades to 37 other objects
398411
DROP EXTENSION pg_pathman CASCADE;
399412
DROP SCHEMA pathman CASCADE;

sql/pathman_runtime_nodes.sql

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ select pathman.create_hash_partitions('test.runtime_test_3', 'id', 4);
261261
create index on test.runtime_test_3 (id);
262262
create index on test.runtime_test_3_0 (id);
263263

264+
create table test.runtime_test_4(val text, id int not null);
265+
insert into test.runtime_test_4(id, val) select * from generate_series(1, 10000) k, md5(k::text);
266+
select pathman.create_range_partitions('test.runtime_test_4', 'id', 1, 2000);
267+
264268

265269
VACUUM ANALYZE;
266270

@@ -274,12 +278,6 @@ select test.pathman_test_3(); /* RuntimeAppend (a join b on a.id = b.val) */
274278
select test.pathman_test_4(); /* RuntimeMergeAppend (lateral) */
275279
select test.pathman_test_5(); /* projection tests for RuntimeXXX nodes */
276280

277-
/* RuntimeAppend (select ... where id = ANY (subquery), missing partitions) */
278-
select count(*) = 0 from pathman.pathman_partition_list
279-
where parent = 'test.runtime_test_1'::regclass and range_max::int < 0;
280-
281-
select from test.runtime_test_1
282-
where id = any (select generate_series(-10, -1)); /* should be empty */
283281

284282
/* RuntimeAppend (join, enabled parent) */
285283
select pathman.set_enable_parent('test.runtime_test_1', true);
@@ -305,6 +303,19 @@ join (select * from test.run_values limit 4) as t2 on t1.id = t2.val;
305303
select generate_series(1, 2) from test.runtime_test_1 as t1
306304
join (select * from test.run_values limit 4) as t2 on t1.id = t2.val;
307305

306+
/* RuntimeAppend (select ... where id = ANY (subquery), missing partitions) */
307+
select count(*) = 0 from pathman.pathman_partition_list
308+
where parent = 'test.runtime_test_4'::regclass and coalesce(range_min::int, 1) < 0;
309+
310+
set enable_hashjoin = off;
311+
set enable_mergejoin = off;
312+
313+
select from test.runtime_test_4
314+
where id = any (select generate_series(-10, -1)); /* should be empty */
315+
316+
set enable_hashjoin = on;
317+
set enable_mergejoin = on;
318+
308319

309320
DROP SCHEMA test CASCADE;
310321
DROP EXTENSION pg_pathman CASCADE;

src/pg_pathman.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ static bool pull_var_param(const WalkerContext *ctx,
7070

7171
static Const *extract_const(WalkerContext *wcxt, Param *param);
7272

73-
static double estimate_paramsel_using_prel(const PartRelationInfo *prel,
74-
int strategy);
75-
7673

7774
/* Copied from PostgreSQL (allpaths.c) */
7875
static void set_plain_rel_size(PlannerInfo *root,
@@ -104,6 +101,21 @@ static void generate_mergeappend_paths(PlannerInfo *root,
104101
((Const *) (node)) \
105102
)
106103

104+
/* Selectivity estimator for common 'paramsel' */
105+
static inline double
106+
estimate_paramsel_using_prel(const PartRelationInfo *prel, int strategy)
107+
{
108+
/* If it's "=", divide by partitions number */
109+
if (strategy == BTEqualStrategyNumber)
110+
return 1.0 / (double) PrelChildrenCount(prel);
111+
112+
/* Default selectivity estimate for inequalities */
113+
else if (prel->parttype == PT_RANGE && strategy > 0)
114+
return DEFAULT_INEQ_SEL;
115+
116+
/* Else there's not much to do */
117+
else return 1.0;
118+
}
107119

108120

109121
/*
@@ -1214,22 +1226,6 @@ extract_const(WalkerContext *wcxt, Param *param)
12141226
value, isnull, get_typbyval(param->paramtype));
12151227
}
12161228

1217-
/* Selectivity estimator for common 'paramsel' */
1218-
static double
1219-
estimate_paramsel_using_prel(const PartRelationInfo *prel, int strategy)
1220-
{
1221-
/* If it's "=", divide by partitions number */
1222-
if (strategy == BTEqualStrategyNumber)
1223-
return 1.0 / (double) PrelChildrenCount(prel);
1224-
1225-
/* Default selectivity estimate for inequalities */
1226-
else if (prel->parttype == PT_RANGE && strategy > 0)
1227-
return DEFAULT_INEQ_SEL;
1228-
1229-
/* Else there's not much to do */
1230-
else return 1.0;
1231-
}
1232-
12331229

12341230

12351231
/*

src/pl_funcs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ show_partition_list_internal(PG_FUNCTION_ARGS)
458458
usercxt = (show_partition_list_cxt *) funccxt->user_fctx;
459459

460460
/* Iterate through pathman cache */
461-
for(;;)
461+
for (;;)
462462
{
463463
const PartRelationInfo *prel;
464464
HeapTuple htup;

0 commit comments

Comments
 (0)