add_satisfies_hash_partition_verification.patch
application/octet-stream
Filename: add_satisfies_hash_partition_verification.patch
Type: application/octet-stream
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/backend/utils/cache/relcache.c | 1 | 1 |
| src/test/regress/expected/partition_prune.out | 36 | 0 |
| src/test/regress/sql/partition_prune.sql | 12 | 0 |
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index e81c4691ec..2a74601fc1 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -1034,7 +1034,7 @@ RelationBuildPartitionKey(Relation relation)
procnum,
format_type_be(opclassform->opcintype))));
- fmgr_info(funcid, &key->partsupfunc[i]);
+ fmgr_info_cxt(funcid, &key->partsupfunc[i], partkeycxt);
/* Collation */
key->partcollation[i] = collation->values[i];
diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out
index eb89a5eb67..ba493f04ab 100644
--- a/src/test/regress/expected/partition_prune.out
+++ b/src/test/regress/expected/partition_prune.out
@@ -1475,6 +1475,12 @@ explain (costs off) select * from hp where a is null and b is null;
Filter: ((a IS NULL) AND (b IS NULL))
(3 rows)
+select satisfies_hash_partition('hp'::regclass, 4, 0, null::int, null::text);
+ satisfies_hash_partition
+--------------------------
+ t
+(1 row)
+
explain (costs off) select * from hp where a = 1 and b is null;
QUERY PLAN
-------------------------------------------
@@ -1483,6 +1489,12 @@ explain (costs off) select * from hp where a = 1 and b is null;
Filter: ((b IS NULL) AND (a = 1))
(3 rows)
+select satisfies_hash_partition('hp'::regclass, 4, 0, 1, null::text);
+ satisfies_hash_partition
+--------------------------
+ t
+(1 row)
+
explain (costs off) select * from hp where a = 1 and b = 'xxx';
QUERY PLAN
-------------------------------------------------
@@ -1491,6 +1503,12 @@ explain (costs off) select * from hp where a = 1 and b = 'xxx';
Filter: ((a = 1) AND (b = 'xxx'::text))
(3 rows)
+select satisfies_hash_partition('hp'::regclass, 4, 3, 1, 'xxx'::text);
+ satisfies_hash_partition
+--------------------------
+ t
+(1 row)
+
explain (costs off) select * from hp where a is null and b = 'xxx';
QUERY PLAN
-----------------------------------------------------
@@ -1499,6 +1517,12 @@ explain (costs off) select * from hp where a is null and b = 'xxx';
Filter: ((a IS NULL) AND (b = 'xxx'::text))
(3 rows)
+select satisfies_hash_partition('hp'::regclass, 4, 2, null::int, 'xxx'::text);
+ satisfies_hash_partition
+--------------------------
+ t
+(1 row)
+
explain (costs off) select * from hp where a = 2 and b = 'xxx';
QUERY PLAN
-------------------------------------------------
@@ -1507,6 +1531,12 @@ explain (costs off) select * from hp where a = 2 and b = 'xxx';
Filter: ((a = 2) AND (b = 'xxx'::text))
(3 rows)
+select satisfies_hash_partition('hp'::regclass, 4, 2, 2, 'xxx'::text);
+ satisfies_hash_partition
+--------------------------
+ t
+(1 row)
+
explain (costs off) select * from hp where a = 1 and b = 'abcde';
QUERY PLAN
---------------------------------------------------
@@ -1515,6 +1545,12 @@ explain (costs off) select * from hp where a = 1 and b = 'abcde';
Filter: ((a = 1) AND (b = 'abcde'::text))
(3 rows)
+select satisfies_hash_partition('hp'::regclass, 4, 1, 1, 'abcde'::text);
+ satisfies_hash_partition
+--------------------------
+ t
+(1 row)
+
explain (costs off) select * from hp where (a = 1 and b = 'abcde') or (a = 2 and b = 'xxx') or (a is null and b is null);
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------
diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql
index 6cc8e3cdfc..787468f290 100644
--- a/src/test/regress/sql/partition_prune.sql
+++ b/src/test/regress/sql/partition_prune.sql
@@ -282,11 +282,23 @@ explain (costs off) select * from hp where a <> 1 and b <> 'xxx';
-- pruning should work if either a value or a IS NULL clause is provided for
-- each of the keys
explain (costs off) select * from hp where a is null and b is null;
+select satisfies_hash_partition('hp'::regclass, 4, 0, null::int, null::text);
+
explain (costs off) select * from hp where a = 1 and b is null;
+select satisfies_hash_partition('hp'::regclass, 4, 0, 1, null::text);
+
explain (costs off) select * from hp where a = 1 and b = 'xxx';
+select satisfies_hash_partition('hp'::regclass, 4, 3, 1, 'xxx'::text);
+
explain (costs off) select * from hp where a is null and b = 'xxx';
+select satisfies_hash_partition('hp'::regclass, 4, 2, null::int, 'xxx'::text);
+
explain (costs off) select * from hp where a = 2 and b = 'xxx';
+select satisfies_hash_partition('hp'::regclass, 4, 2, 2, 'xxx'::text);
+
explain (costs off) select * from hp where a = 1 and b = 'abcde';
+select satisfies_hash_partition('hp'::regclass, 4, 1, 1, 'abcde'::text);
+
explain (costs off) select * from hp where (a = 1 and b = 'abcde') or (a = 2 and b = 'xxx') or (a is null and b is null);
drop table hp;