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

Commitdb3508e

Browse files
committed
add tests for ON CONFLICT (unsupported), fix {incr, decr}_refcount_parenthood_statuses() and pathman_planner_hook()
1 parent967d13f commitdb3508e

File tree

6 files changed

+75
-44
lines changed

6 files changed

+75
-44
lines changed

‎expected/pathman_basic.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ UNION SELECT * FROM test.from_only_test;
494494
/* not ok, ONLY|non-ONLY in one query */
495495
EXPLAIN (COSTS OFF)
496496
SELECT * FROM test.from_only_test a JOIN ONLY test.from_only_test b USING(val);
497-
ERROR:It is prohibited to apply ONLY modifier to partitioned tables which have already been mentioned without ONLY
497+
ERROR:it is prohibited to apply ONLY modifier to partitioned tables which have already been mentioned without ONLY
498498
EXPLAIN (COSTS OFF)
499499
WITH q1 AS (SELECT * FROM test.from_only_test),
500500
q2 AS (SELECT * FROM ONLY test.from_only_test)

‎expected/pathman_inserts.out

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ CREATE SCHEMA test_inserts;
55
/* create a partitioned table */
66
CREATE TABLE test_inserts.storage(a INT4, b INT4 NOT NULL, c NUMERIC, d TEXT);
77
INSERT INTO test_inserts.storage SELECT i * 2, i, i, i::text FROM generate_series(1, 100) i;
8+
CREATE UNIQUE INDEX ON test_inserts.storage(a);
89
SELECT create_range_partitions('test_inserts.storage', 'b', 1, 10);
910
NOTICE: sequence "storage_seq" does not exist, skipping
1011
create_range_partitions
1112
-------------------------
1213
10
1314
(1 row)
1415

16+
/* we don't support ON CONLICT */
17+
INSERT INTO test_inserts.storage VALUES(0, 0, 0, 'UNSUPPORTED_1')
18+
ON CONFLICT (a) DO UPDATE SET a = 3;
19+
ERROR: ON CONFLICT clause is not supported with partitioned tables
20+
INSERT INTO test_inserts.storage VALUES(0, 0, 0, 'UNSUPPORTED_2')
21+
ON CONFLICT (a) DO NOTHING;
22+
ERROR: ON CONFLICT clause is not supported with partitioned tables
1523
/* implicitly prepend a partition (no columns have been dropped yet) */
1624
INSERT INTO test_inserts.storage VALUES(0, 0, 0, 'PREPEND.') RETURNING *;
1725
a | b | c | d
@@ -25,7 +33,7 @@ SELECT * FROM test_inserts.storage_11;
2533
0 | 0 | 0 | PREPEND.
2634
(1 row)
2735

28-
INSERT INTO test_inserts.storage VALUES(0, 0, 0, 'PREPEND..') RETURNING tableoid::regclass;
36+
INSERT INTO test_inserts.storage VALUES(1, 0, 0, 'PREPEND..') RETURNING tableoid::regclass;
2937
tableoid
3038
-------------------------
3139
test_inserts.storage_11
@@ -35,7 +43,7 @@ SELECT * FROM test_inserts.storage_11;
3543
a | b | c | d
3644
---+---+---+-----------
3745
0 | 0 | 0 | PREPEND.
38-
0 | 0 | 0 | PREPEND..
46+
1 | 0 | 0 | PREPEND..
3947
(2 rows)
4048

4149
INSERT INTO test_inserts.storage VALUES(3, 0, 0, 'PREPEND...') RETURNING a + b / 3;
@@ -48,10 +56,13 @@ SELECT * FROM test_inserts.storage_11;
4856
a | b | c | d
4957
---+---+---+------------
5058
0 | 0 | 0 | PREPEND.
51-
0 | 0 | 0 | PREPEND..
59+
1 | 0 | 0 | PREPEND..
5260
3 | 0 | 0 | PREPEND...
5361
(3 rows)
5462

63+
/* cause a conflict (a = 0) */
64+
INSERT INTO test_inserts.storage VALUES(0, 0, 0, 'CONFLICT') RETURNING *;
65+
ERROR: duplicate key value violates unique constraint "storage_11_a_idx"
5566
/* drop first column */
5667
ALTER TABLE test_inserts.storage DROP COLUMN a CASCADE;
5768
/* will have 3 columns (b, c, d) */

‎sql/pathman_inserts.sql

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,30 @@ CREATE SCHEMA test_inserts;
88
/* create a partitioned table*/
99
CREATETABLEtest_inserts.storage(a INT4, b INT4NOT NULL, cNUMERIC, dTEXT);
1010
INSERT INTOtest_inserts.storageSELECT i*2, i, i, i::textFROM generate_series(1,100) i;
11+
CREATEUNIQUE INDEXONtest_inserts.storage(a);
1112
SELECT create_range_partitions('test_inserts.storage','b',1,10);
1213

1314

15+
/* we don't support ON CONLICT*/
16+
INSERT INTOtest_inserts.storageVALUES(0,0,0,'UNSUPPORTED_1')
17+
ON CONFLICT (a) DOUPDATESET a=3;
18+
INSERT INTOtest_inserts.storageVALUES(0,0,0,'UNSUPPORTED_2')
19+
ON CONFLICT (a) DO NOTHING;
20+
21+
1422
/* implicitly prepend a partition (no columns have been dropped yet)*/
1523
INSERT INTOtest_inserts.storageVALUES(0,0,0,'PREPEND.') RETURNING*;
1624
SELECT*FROMtest_inserts.storage_11;
1725

18-
INSERT INTOtest_inserts.storageVALUES(0,0,0,'PREPEND..') RETURNING tableoid::regclass;
26+
INSERT INTOtest_inserts.storageVALUES(1,0,0,'PREPEND..') RETURNING tableoid::regclass;
1927
SELECT*FROMtest_inserts.storage_11;
2028

2129
INSERT INTOtest_inserts.storageVALUES(3,0,0,'PREPEND...') RETURNING a+ b/3;
2230
SELECT*FROMtest_inserts.storage_11;
2331

32+
/* cause a conflict (a = 0)*/
33+
INSERT INTOtest_inserts.storageVALUES(0,0,0,'CONFLICT') RETURNING*;
34+
2435

2536
/* drop first column*/
2637
ALTERTABLEtest_inserts.storage DROP COLUMN a CASCADE;

‎src/hooks.c

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -466,39 +466,52 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
466466
proc((planned_stmt)->rtable, (Plan *) lfirst(lc)); \
467467
} while (0)
468468

469-
PlannedStmt*result;
470-
uint32query_id=parse->queryId;
469+
PlannedStmt*result;
470+
uint32query_id=parse->queryId;
471471

472-
if (IsPathmanReady())
472+
PG_TRY();
473473
{
474-
/* Increment parenthood_statuses refcount */
475-
incr_refcount_parenthood_statuses();
474+
if (IsPathmanReady())
475+
{
476+
/* Increment parenthood_statuses refcount */
477+
incr_refcount_parenthood_statuses();
476478

477-
/* Modify query tree if needed */
478-
pathman_transform_query(parse);
479-
}
479+
/* Modify query tree if needed */
480+
pathman_transform_query(parse);
481+
}
480482

481-
/* Invoke original hook if needed */
482-
if (planner_hook_next)
483-
result=planner_hook_next(parse,cursorOptions,boundParams);
484-
else
485-
result=standard_planner(parse,cursorOptions,boundParams);
483+
/* Invoke original hook if needed */
484+
if (planner_hook_next)
485+
result=planner_hook_next(parse,cursorOptions,boundParams);
486+
else
487+
result=standard_planner(parse,cursorOptions,boundParams);
486488

487-
if (IsPathmanReady())
488-
{
489-
/* Give rowmark-related attributes correct names */
490-
ExecuteForPlanTree(result,postprocess_lock_rows);
489+
if (IsPathmanReady())
490+
{
491+
/* Give rowmark-related attributes correct names */
492+
ExecuteForPlanTree(result,postprocess_lock_rows);
493+
494+
/* Add PartitionFilter node for INSERT queries */
495+
ExecuteForPlanTree(result,add_partition_filters);
491496

492-
/*Add PartitionFilter node for INSERT queries */
493-
ExecuteForPlanTree(result,add_partition_filters);
497+
/*Decrement parenthood_statuses refcount */
498+
decr_refcount_parenthood_statuses();
494499

495-
/* Decrement parenthood_statuses refcount */
496-
decr_refcount_parenthood_statuses(false);
500+
/* HACK: restore queryId set by pg_stat_statements */
501+
result->queryId=query_id;
502+
}
503+
}
504+
/* We must decrease parenthood statuses refcount on ERROR */
505+
PG_CATCH();
506+
{
507+
/* Caught an ERROR, decrease refcount */
508+
decr_refcount_parenthood_statuses();
497509

498-
/* HACK: restore queryId set by pg_stat_statements */
499-
result->queryId=query_id;
510+
PG_RE_THROW();
500511
}
512+
PG_END_TRY();
501513

514+
/* Finally return the Plan */
502515
returnresult;
503516
}
504517

‎src/planner_tree_modification.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static List *get_tableoids_list(List *tlist);
4343
* cant't be used with both and without ONLY modifiers.
4444
*/
4545
staticHTAB*per_table_parenthood_mapping=NULL;
46-
staticuint32per_table_parenthood_mapping_refcount=0;
46+
staticintper_table_parenthood_mapping_refcount=0;
4747

4848
/*
4949
* We have to mark each Query with a unique id in order
@@ -564,10 +564,7 @@ assign_rel_parenthood_status(uint32 query_id,
564564
/* Saved status conflicts with 'new_status' */
565565
if (status_entry->parenthood_status!=new_status)
566566
{
567-
/* Don't forget to clear ALL tracked statuses! */
568-
decr_refcount_parenthood_statuses(true);
569-
570-
elog(ERROR,"It is prohibited to apply ONLY modifier to partitioned "
567+
elog(ERROR,"it is prohibited to apply ONLY modifier to partitioned "
571568
"tables which have already been mentioned without ONLY");
572569
}
573570
}
@@ -612,8 +609,10 @@ get_rel_parenthood_status(uint32 query_id, Oid relid)
612609
void
613610
incr_refcount_parenthood_statuses(void)
614611
{
615-
Assert(per_table_parenthood_mapping_refcount >=0);
616-
per_table_parenthood_mapping_refcount++;
612+
/* Increment reference counter */
613+
if (++per_table_parenthood_mapping_refcount <=0)
614+
elog(WARNING,"imbalanced %s",
615+
CppAsString(incr_refcount_parenthood_statuses));
617616
}
618617

619618
/* Return current value of usage counter */
@@ -626,15 +625,12 @@ get_refcount_parenthood_statuses(void)
626625

627626
/* Reset all cached statuses if needed (query end) */
628627
void
629-
decr_refcount_parenthood_statuses(boolentirely)
628+
decr_refcount_parenthood_statuses(void)
630629
{
631-
Assert(per_table_parenthood_mapping_refcount>0);
632-
633-
/* Should we destroy the table right now? */
634-
if (entirely)
635-
per_table_parenthood_mapping_refcount=0;
636-
else
637-
per_table_parenthood_mapping_refcount--;
630+
/* Decrement reference counter */
631+
if (--per_table_parenthood_mapping_refcount<0)
632+
elog(WARNING,"imbalanced %s",
633+
CppAsString(decr_refcount_parenthood_statuses));
638634

639635
/* Free resources if no one is using them */
640636
if (per_table_parenthood_mapping_refcount==0)

‎src/planner_tree_modification.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void assign_rel_parenthood_status(uint32 query_id, Oid relid,
4646
rel_parenthood_statusget_rel_parenthood_status(uint32query_id,Oidrelid);
4747
voidincr_refcount_parenthood_statuses(void);
4848
uint32get_refcount_parenthood_statuses(void);
49-
voiddecr_refcount_parenthood_statuses(boolentirely);
49+
voiddecr_refcount_parenthood_statuses(void);
5050

5151

5252
#endif/* PLANNER_TREE_MODIFICATION_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp