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

Commitd038dab

Browse files
committed
Merge branch 'rel_1_3_beta' into master_pg_upgrade_bug
2 parents59778f5 +a93a846 commitd038dab

13 files changed

+582
-35
lines changed

‎expected/pathman_basic.out

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2309,7 +2309,45 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.index_on_childs WHERE c1 > 100 AND c1 < 2
23092309
Filter: (c1 < 2500)
23102310
(12 rows)
23112311

2312+
/* Test recursive CTE */
2313+
CREATE TABLE test.recursive_cte_test_tbl(id INT NOT NULL, name TEXT NOT NULL);
2314+
SELECT * FROM create_hash_partitions('test.recursive_cte_test_tbl', 'id', 2);
2315+
create_hash_partitions
2316+
------------------------
2317+
2
2318+
(1 row)
2319+
2320+
INSERT INTO test.recursive_cte_test_tbl (id, name) SELECT id, 'name'||id FROM generate_series(1,100) f(id);
2321+
INSERT INTO test.recursive_cte_test_tbl (id, name) SELECT id, 'name'||(id + 1) FROM generate_series(1,100) f(id);
2322+
INSERT INTO test.recursive_cte_test_tbl (id, name) SELECT id, 'name'||(id + 2) FROM generate_series(1,100) f(id);
2323+
SELECT * FROM test.recursive_cte_test_tbl WHERE id = 5;
2324+
id | name
2325+
----+-------
2326+
5 | name5
2327+
5 | name6
2328+
5 | name7
2329+
(3 rows)
2330+
2331+
WITH RECURSIVE test AS (
2332+
SELECT min(name) AS name
2333+
FROM test.recursive_cte_test_tbl
2334+
WHERE id = 5
2335+
UNION ALL
2336+
SELECT (SELECT min(name)
2337+
FROM test.recursive_cte_test_tbl
2338+
WHERE id = 5 AND name > test.name)
2339+
FROM test
2340+
WHERE name IS NOT NULL)
2341+
SELECT * FROM test;
2342+
name
2343+
-------
2344+
name5
2345+
name6
2346+
name7
2347+
2348+
(4 rows)
2349+
23122350
DROP SCHEMA test CASCADE;
2313-
NOTICE: drop cascades to51 other objects
2351+
NOTICE: drop cascades to54 other objects
23142352
DROP EXTENSION pg_pathman CASCADE;
23152353
DROP SCHEMA pathman CASCADE;

‎expected/pathman_inserts.out

Lines changed: 219 additions & 3 deletions
Large diffs are not rendered by default.

‎sql/pathman_basic.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,27 @@ SELECT set_enable_parent('test.index_on_childs', true);
660660
VACUUM ANALYZEtest.index_on_childs;
661661
EXPLAIN (COSTS OFF)SELECT*FROMtest.index_on_childsWHERE c1>100AND c1<2500AND c2=500;
662662

663+
/* Test recursive CTE*/
664+
CREATETABLEtest.recursive_cte_test_tbl(idINTNOT NULL, nameTEXTNOT NULL);
665+
SELECT*FROM create_hash_partitions('test.recursive_cte_test_tbl','id',2);
666+
INSERT INTOtest.recursive_cte_test_tbl (id, name)SELECT id,'name'||idFROM generate_series(1,100) f(id);
667+
INSERT INTOtest.recursive_cte_test_tbl (id, name)SELECT id,'name'||(id+1)FROM generate_series(1,100) f(id);
668+
INSERT INTOtest.recursive_cte_test_tbl (id, name)SELECT id,'name'||(id+2)FROM generate_series(1,100) f(id);
669+
SELECT*FROMtest.recursive_cte_test_tblWHERE id=5;
670+
671+
WITH RECURSIVE testAS (
672+
SELECTmin(name)AS name
673+
FROMtest.recursive_cte_test_tbl
674+
WHERE id=5
675+
UNION ALL
676+
SELECT (SELECTmin(name)
677+
FROMtest.recursive_cte_test_tbl
678+
WHERE id=5AND name>test.name)
679+
FROM test
680+
WHERE nameIS NOT NULL)
681+
SELECT*FROM test;
682+
683+
663684
DROPSCHEMA test CASCADE;
664685
DROP EXTENSION pg_pathman CASCADE;
665686
DROPSCHEMA pathman CASCADE;

‎sql/pathman_inserts.sql

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,34 @@ INSERT INTO test_inserts.storage SELECT i * 2, i, i, i::text FROM generate_serie
1111
CREATEUNIQUE INDEXONtest_inserts.storage(a);
1212
SELECT create_range_partitions('test_inserts.storage','b',1,10);
1313

14+
/*
15+
* attach before and after insertion triggers to partitioned table
16+
*/
17+
/* prepare trigger functions*/
18+
CREATE OR REPLACEFUNCTIONtest_inserts.print_cols_before_change() RETURNS TRIGGERAS $$
19+
BEGIN
20+
RAISE NOTICE'BEFORE INSERTION TRIGGER ON TABLE % HAS EXPIRED. INSERTED ROW: %', tg_table_name, new;
21+
RETURN new;
22+
END;
23+
$$ LANGUAGE plpgsql;
24+
CREATE OR REPLACEFUNCTIONtest_inserts.print_cols_after_change() RETURNS TRIGGERAS $$
25+
BEGIN
26+
RAISE NOTICE'AFTER INSERTION TRIGGER ON TABLE % HAS EXPIRED. INSERTED ROW: %', tg_table_name, new;
27+
RETURN new;
28+
END;
29+
$$ LANGUAGE plpgsql;
30+
/* set triggers on existing first partition and new generated partitions*/
31+
CREATETRIGGERprint_new_row_before_insert BEFORE INSERTONtest_inserts.storage_1
32+
FOR EACH ROW EXECUTE PROCEDUREtest_inserts.print_cols_before_change();
33+
CREATETRIGGERprint_new_row_after_insert AFTER INSERTONtest_inserts.storage_1
34+
FOR EACH ROW EXECUTE PROCEDUREtest_inserts.print_cols_after_change();
35+
CREATE OR REPLACEFUNCTIONtest_inserts.set_triggers(args jsonb) RETURNS VOIDAS $$
36+
BEGIN
37+
EXECUTE format('create trigger print_new_row_before_insert before insert on %s.%s for each row execute procedure test_inserts.print_cols_before_change();', args->>'partition_schema', args->>'partition');
38+
EXECUTE format('create trigger print_new_row_after_insert after insert on %s.%s for each row execute procedure test_inserts.print_cols_after_change();', args->>'partition_schema', args->>'partition');
39+
END;
40+
$$ LANGUAGE plpgsql;
41+
SELECT set_init_callback('test_inserts.storage','test_inserts.set_triggers');
1442

1543
/* we don't support ON CONLICT*/
1644
INSERT INTOtest_inserts.storageVALUES(0,0,0,'UNSUPPORTED_1')
@@ -29,7 +57,7 @@ SELECT * FROM test_inserts.storage_11;
2957
INSERT INTOtest_inserts.storageVALUES(3,0,0,'PREPEND...') RETURNING a+ b/3;
3058
SELECT*FROMtest_inserts.storage_11;
3159

32-
/* causea conflict (a = 0)*/
60+
/* causean unique index conflict (a = 0)*/
3361
INSERT INTOtest_inserts.storageVALUES(0,0,0,'CONFLICT') RETURNING*;
3462

3563

@@ -59,7 +87,7 @@ INSERT INTO test_inserts.storage VALUES(111, 0, 'DROP_COL_1...') RETURNING b * 2
5987
ALTERTABLEtest_inserts.storage DROP COLUMN c CASCADE;
6088

6189

62-
/* will have3 columns (b, c, d)*/
90+
/* will have2 columns (b, d)*/
6391
SELECT append_range_partition('test_inserts.storage');
6492
INSERT INTOtest_inserts.storage (b, d)VALUES (121,'2 cols!');
6593
SELECT*FROMtest_inserts.storage_14;/* direct access*/

‎src/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ pathman_relcache_hook(Datum arg, Oid relid)
605605
return;
606606

607607
/* Invalidation event for PATHMAN_CONFIG table (probably DROP) */
608-
if (relid==get_pathman_config_relid())
608+
if (relid==get_pathman_config_relid(false))
609609
delay_pathman_shutdown();
610610

611611
/* Invalidate PartParentInfo cache if needed */

‎src/init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
676676
ObjectIdGetDatum(relid));
677677

678678
/* Open PATHMAN_CONFIG with latest snapshot available */
679-
rel=heap_open(get_pathman_config_relid(),AccessShareLock);
679+
rel=heap_open(get_pathman_config_relid(false),AccessShareLock);
680680

681681
/* Check that 'partrel' column is if regclass type */
682682
Assert(RelationGetDescr(rel)->
@@ -750,7 +750,7 @@ read_pathman_params(Oid relid, Datum *values, bool *isnull)
750750
BTEqualStrategyNumber,F_OIDEQ,
751751
ObjectIdGetDatum(relid));
752752

753-
rel=heap_open(get_pathman_config_params_relid(),AccessShareLock);
753+
rel=heap_open(get_pathman_config_params_relid(false),AccessShareLock);
754754
snapshot=RegisterSnapshot(GetLatestSnapshot());
755755
scan=heap_beginscan(rel,snapshot,1,key);
756756

@@ -788,7 +788,7 @@ read_pathman_config(void)
788788
HeapTuplehtup;
789789

790790
/* Open PATHMAN_CONFIG with latest snapshot available */
791-
rel=heap_open(get_pathman_config_relid(),AccessShareLock);
791+
rel=heap_open(get_pathman_config_relid(false),AccessShareLock);
792792

793793
/* Check that 'partrel' column is if regclass type */
794794
Assert(RelationGetDescr(rel)->

‎src/pathman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ extern Oidpathman_config_params_relid;
8585
/*
8686
* Just to clarify our intentions (return the corresponding relid).
8787
*/
88-
Oidget_pathman_config_relid(void);
89-
Oidget_pathman_config_params_relid(void);
88+
Oidget_pathman_config_relid(boolinvalid_is_ok);
89+
Oidget_pathman_config_params_relid(boolinvalid_is_ok);
9090

9191
/*
9292
* pg_pathman's global state structure.

‎src/pg_pathman.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,16 +1922,32 @@ generate_mergeappend_paths(PlannerInfo *root, RelOptInfo *rel,
19221922
* Get cached PATHMAN_CONFIG relation Oid.
19231923
*/
19241924
Oid
1925-
get_pathman_config_relid(void)
1925+
get_pathman_config_relid(boolinvalid_is_ok)
19261926
{
1927+
/* Raise ERROR if Oid is invalid */
1928+
if (!OidIsValid(pathman_config_relid)&& !invalid_is_ok)
1929+
elog(ERROR,
1930+
(!IsPathmanInitialized() ?
1931+
"pg_pathman is not initialized yet" :
1932+
"unexpected error in function "
1933+
CppAsString(get_pathman_config_relid)));
1934+
19271935
returnpathman_config_relid;
19281936
}
19291937

19301938
/*
19311939
* Get cached PATHMAN_CONFIG_PARAMS relation Oid.
19321940
*/
19331941
Oid
1934-
get_pathman_config_params_relid(void)
1942+
get_pathman_config_params_relid(boolinvalid_is_ok)
19351943
{
1944+
/* Raise ERROR if Oid is invalid */
1945+
if (!OidIsValid(pathman_config_relid)&& !invalid_is_ok)
1946+
elog(ERROR,
1947+
(!IsPathmanInitialized() ?
1948+
"pg_pathman is not initialized yet" :
1949+
"unexpected error in function "
1950+
CppAsString(get_pathman_config_params_relid)));
1951+
19361952
returnpathman_config_params_relid;
19371953
}

‎src/pl_funcs.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ show_partition_list_internal(PG_FUNCTION_ARGS)
285285
usercxt= (show_partition_list_cxt*)palloc(sizeof(show_partition_list_cxt));
286286

287287
/* Open PATHMAN_CONFIG with latest snapshot available */
288-
usercxt->pathman_config=heap_open(get_pathman_config_relid(),
288+
usercxt->pathman_config=heap_open(get_pathman_config_relid(false),
289289
AccessShareLock);
290290
usercxt->snapshot=RegisterSnapshot(GetLatestSnapshot());
291291
usercxt->pathman_config_scan=heap_beginscan(usercxt->pathman_config,
@@ -637,7 +637,7 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
637637
isnull[Anum_pathman_config_range_interval-1]=PG_ARGISNULL(2);
638638

639639
/* Insert new row into PATHMAN_CONFIG */
640-
pathman_config=heap_open(get_pathman_config_relid(),RowExclusiveLock);
640+
pathman_config=heap_open(get_pathman_config_relid(false),RowExclusiveLock);
641641
htup=heap_form_tuple(RelationGetDescr(pathman_config),values,isnull);
642642
simple_heap_insert(pathman_config,htup);
643643
indstate=CatalogOpenIndexes(pathman_config);
@@ -685,11 +685,18 @@ Datum
685685
pathman_config_params_trigger_func(PG_FUNCTION_ARGS)
686686
{
687687
TriggerData*trigdata= (TriggerData*)fcinfo->context;
688-
Oidpathman_config_params=get_pathman_config_params_relid();
688+
Oidpathman_config_params;
689689
Oidpartrel;
690690
Datumpartrel_datum;
691691
boolpartrel_isnull;
692692

693+
/* Fetch Oid of PATHMAN_CONFIG_PARAMS */
694+
pathman_config_params=get_pathman_config_params_relid(true);
695+
696+
/* Handle "pg_pathman.enabled = t" case */
697+
if (!OidIsValid(pathman_config_params))
698+
gotopathman_config_params_trigger_func_return;
699+
693700
/* Handle user calls */
694701
if (!CALLED_AS_TRIGGER(fcinfo))
695702
elog(ERROR,"this function should not be called directly");
@@ -718,6 +725,7 @@ pathman_config_params_trigger_func(PG_FUNCTION_ARGS)
718725
if (check_relation_exists(partrel))
719726
CacheInvalidateRelcacheByRelid(partrel);
720727

728+
pathman_config_params_trigger_func_return:
721729
/* Return the tuple we've been given */
722730
if (trigdata->tg_event&TRIGGER_EVENT_UPDATE)
723731
PG_RETURN_POINTER(trigdata->tg_newtuple);

‎src/relation_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ finish_delayed_invalidation(void)
417417

418418
/* Check that PATHMAN_CONFIG table has indeed been dropped */
419419
if (cur_pathman_config_relid==InvalidOid||
420-
cur_pathman_config_relid!=get_pathman_config_relid())
420+
cur_pathman_config_relid!=get_pathman_config_relid(true))
421421
{
422422
/* Ok, let's unload pg_pathman's config */
423423
unload_config();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp