diff options
author | Tom Lane | 2019-12-25 20:44:15 +0000 |
---|---|---|
committer | Tom Lane | 2019-12-25 20:44:15 +0000 |
commit | bb4114a4e2c65f27931cc074214c051dba2876c3 (patch) | |
tree | f197bcc85c7479e20905e9f821893d5c49eb67b3 /src/test | |
parent | 42f74f49367bee1d3da28c4b383faec29364f320 (diff) |
Allow whole-row Vars to be used in partitioning expressions.
In the wake of commit 5b9312378, there's no particular reason
for this restriction (previously, it was problematic because of
the implied rowtype reference). A simple constraint on a whole-row
Var probably isn't that useful, but conceivably somebody would want
to pass one to a function that extracts a partitioning key. Besides
which, we're expending much more code to enforce the restriction than
we save by having it, since the latter quantity is now zero.
So drop the restriction.
Amit Langote
Discussion: https://postgr.es/m/CA+HiwqFUzjfj9HEsJtYWcr1SgQ_=iCAvQ=O2Sx6aQxoDu4OiHw@mail.gmail.com
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/regress/expected/create_table.out | 30 | ||||
-rw-r--r-- | src/test/regress/sql/create_table.sql | 17 |
2 files changed, 37 insertions, 10 deletions
diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out index 5236038901b..b64f91955d1 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -420,11 +420,6 @@ CREATE TABLE partitioned ( ) PARTITION BY RANGE (immut_func(a)); ERROR: functions in partition key expression must be marked IMMUTABLE DROP FUNCTION immut_func(int); --- cannot contain whole-row references -CREATE TABLE partitioned ( - a int -) PARTITION BY RANGE ((partitioned)); -ERROR: partition key expressions cannot contain whole-row references -- prevent using columns of unsupported types in key (type must have a btree operator class) CREATE TABLE partitioned ( a point @@ -528,6 +523,31 @@ select * from partitioned where row(a,b)::partitioned = '(1,2)'::partitioned; (2 rows) drop table partitioned; +-- whole-row Var in partition key works too +create table partitioned (a int, b int) + partition by list ((partitioned)); +create table partitioned1 + partition of partitioned for values in ('(1,2)'); +create table partitioned2 + partition of partitioned for values in ('(2,4)'); +explain (costs off) +select * from partitioned where partitioned = '(1,2)'::partitioned; + QUERY PLAN +----------------------------------------------------------------- + Seq Scan on partitioned1 partitioned + Filter: ((partitioned.*)::partitioned = '(1,2)'::partitioned) +(2 rows) + +\d+ partitioned1 + Table "public.partitioned1" + Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+---------+-----------+----------+---------+---------+--------------+------------- + a | integer | | | | plain | | + b | integer | | | | plain | | +Partition of: partitioned FOR VALUES IN ('(1,2)') +Partition constraint: (((partitioned1.*)::partitioned IS DISTINCT FROM NULL) AND ((partitioned1.*)::partitioned = '(1,2)'::partitioned)) + +drop table partitioned; -- check that dependencies of partition columns are handled correctly create domain intdom1 as int; create table partitioned ( diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/create_table.sql index ab424dcddfd..00ef81a6850 100644 --- a/src/test/regress/sql/create_table.sql +++ b/src/test/regress/sql/create_table.sql @@ -401,11 +401,6 @@ CREATE TABLE partitioned ( ) PARTITION BY RANGE (immut_func(a)); DROP FUNCTION immut_func(int); --- cannot contain whole-row references -CREATE TABLE partitioned ( - a int -) PARTITION BY RANGE ((partitioned)); - -- prevent using columns of unsupported types in key (type must have a btree operator class) CREATE TABLE partitioned ( a point @@ -470,6 +465,18 @@ explain (costs off) select * from partitioned where row(a,b)::partitioned = '(1,2)'::partitioned; drop table partitioned; +-- whole-row Var in partition key works too +create table partitioned (a int, b int) + partition by list ((partitioned)); +create table partitioned1 + partition of partitioned for values in ('(1,2)'); +create table partitioned2 + partition of partitioned for values in ('(2,4)'); +explain (costs off) +select * from partitioned where partitioned = '(1,2)'::partitioned; +\d+ partitioned1 +drop table partitioned; + -- check that dependencies of partition columns are handled correctly create domain intdom1 as int; |