Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d5fede

Browse files
committed
Code review forc94e694.
validateCheckConstraint() shouldn't try to access the storage fora partitioned table, because it no longer has any. Creating a_RETURN table on a partitioned table shouldn't be allowed, bothbecause there's no value in it and because trying to do so wouldinvolve a validation scan against its nonexistent storage.Amit Langote, reviewed by Tom Lane. Regression test outputsupdated to pass by me.Discussion:http://postgr.es/m/e5c3cbd3-1551-d6f8-c9e2-51777d632fd2@lab.ntt.co.jp
1 parentb935eb7 commit1d5fede

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8120,8 +8120,12 @@ validateCheckConstraint(Relation rel, HeapTuple constrtup)
81208120
boolisnull;
81218121
Snapshotsnapshot;
81228122

8123-
/* VALIDATE CONSTRAINT is a no-op for foreign tables */
8124-
if (rel->rd_rel->relkind==RELKIND_FOREIGN_TABLE)
8123+
/*
8124+
* VALIDATE CONSTRAINT is a no-op for foreign tables and partitioned
8125+
* tables.
8126+
*/
8127+
if (rel->rd_rel->relkind==RELKIND_FOREIGN_TABLE||
8128+
rel->rd_rel->relkind==RELKIND_PARTITIONED_TABLE)
81258129
return;
81268130

81278131
constrForm= (Form_pg_constraint)GETSTRUCT(constrtup);

‎src/backend/rewrite/rewriteDefine.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,12 @@ DefineQueryRewrite(char *rulename,
422422
HeapScanDescscanDesc;
423423
Snapshotsnapshot;
424424

425+
if (event_relation->rd_rel->relkind==RELKIND_PARTITIONED_TABLE)
426+
ereport(ERROR,
427+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
428+
errmsg("could not convert partitioned table \"%s\" to a view",
429+
RelationGetRelationName(event_relation))));
430+
425431
snapshot=RegisterSnapshot(GetLatestSnapshot());
426432
scanDesc=heap_beginscan(event_relation,snapshot,0,NULL);
427433
if (heap_getnext(scanDesc,ForwardScanDirection)!=NULL)

‎src/test/regress/expected/alter_table.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3372,3 +3372,9 @@ ERROR: partition constraint is violated by some row
33723372
-- cleanup
33733373
drop table p;
33743374
drop table p1;
3375+
-- validate constraint on partitioned tables should only scan leaf partitions
3376+
create table parted_validate_test (a int) partition by list (a);
3377+
create table parted_validate_test_1 partition of parted_validate_test for values in (0, 1);
3378+
alter table parted_validate_test add constraint parted_validate_test_chka check (a > 0) not valid;
3379+
alter table parted_validate_test validate constraint parted_validate_test_chka;
3380+
drop table parted_validate_test;

‎src/test/regress/expected/rules.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,6 +2574,11 @@ select reltoastrelid, relkind, relfrozenxid
25742574
(1 row)
25752575

25762576
drop view fooview;
2577+
-- trying to convert a partitioned table to view is not allowed
2578+
create table fooview (x int, y text) partition by list (x);
2579+
create rule "_RETURN" as on select to fooview do instead
2580+
select 1 as x, 'aaa'::text as y;
2581+
ERROR: could not convert partitioned table "fooview" to a view
25772582
--
25782583
-- check for planner problems with complex inherited UPDATES
25792584
--

‎src/test/regress/sql/alter_table.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,3 +2228,10 @@ alter table p attach partition p1 for values from (1, 2) to (1, 10);
22282228
-- cleanup
22292229
droptable p;
22302230
droptable p1;
2231+
2232+
-- validate constraint on partitioned tables should only scan leaf partitions
2233+
createtableparted_validate_test (aint) partition by list (a);
2234+
createtableparted_validate_test_1 partition of parted_validate_test forvaluesin (0,1);
2235+
altertable parted_validate_test addconstraint parted_validate_test_chkacheck (a>0) not valid;
2236+
altertable parted_validate_test validateconstraint parted_validate_test_chka;
2237+
droptable parted_validate_test;

‎src/test/regress/sql/rules.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,11 @@ select reltoastrelid, relkind, relfrozenxid
898898

899899
dropview fooview;
900900

901+
-- trying to convert a partitioned table to view is not allowed
902+
createtablefooview (xint, ytext) partition by list (x);
903+
createrule "_RETURN"asonselect to fooview do instead
904+
select1as x,'aaa'::textas y;
905+
901906
--
902907
-- check for planner problems with complex inherited UPDATES
903908
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp