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

Commitc36721e

Browse files
committed
pathman:
* fix ONLY statement* partition_data PL-function
1 parent345ca19 commitc36721e

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

‎contrib/pathman/pathman.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static void append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
5252
staticNode*wrapper_make_expression(WrapperNode*wrap,intindex,bool*alwaysTrue);
5353
staticvoidset_pathkeys(PlannerInfo*root,RelOptInfo*childrel,Path*path);
5454
staticvoiddisable_inheritance(Query*parse);
55+
boolinheritance_disabled;
5556

5657
staticWrapperNode*walk_expr_tree(Expr*expr,constPartRelationInfo*prel);
5758
staticintmake_hash(constPartRelationInfo*prel,intvalue);
@@ -127,6 +128,7 @@ my_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
127128
if (initialization_needed)
128129
init();
129130

131+
inheritance_disabled= false;
130132
disable_inheritance(parse);
131133
result=standard_planner(parse,cursorOptions,boundParams);
132134
returnresult;
@@ -157,7 +159,16 @@ disable_inheritance(Query *parse)
157159
prel= (PartRelationInfo*)
158160
hash_search(relations, (constvoid*)&rte->relid,HASH_FIND,0);
159161
if (prel!=NULL)
162+
{
160163
rte->inh= false;
164+
/*
165+
* Sometimes user uses the ONLY statement and in this case
166+
* rte->inh is also false. We should differ the case
167+
* when user uses ONLY statement from case when we
168+
* make rte->inh false intentionally.
169+
*/
170+
inheritance_disabled= true;
171+
}
161172
}
162173
break;
163174
caseRTE_SUBQUERY:
@@ -198,7 +209,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
198209
PartRelationInfo*prel=NULL;
199210

200211
/* This works on for SELECT queries */
201-
if (root->parse->commandType!=CMD_SELECT)
212+
if (root->parse->commandType!=CMD_SELECT|| !inheritance_disabled)
202213
return;
203214

204215
/* Lookup partitioning information for parent relation */

‎contrib/pathman/sql/init.sql

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS @extschema@.pg_pathman_rels (
55
idSERIALPRIMARY KEY,
66
relnameVARCHAR(127),
77
attnameVARCHAR(127),
8-
atttypeINTEGER,
8+
--atttype INTEGER,
99
parttypeINTEGER
1010
);
1111

@@ -169,6 +169,34 @@ RETURNS VOID AS 'pathman', 'on_partitions_removed' LANGUAGE C STRICT;
169169
CREATE OR REPLACEFUNCTIONfind_range_partition(relidOID, value ANYELEMENT)
170170
RETURNSOIDAS'pathman','find_range_partition' LANGUAGE C STRICT;
171171

172+
CREATE OR REPLACEFUNCTIONpartition_data(p_parenttext)
173+
RETURNSbigintAS
174+
$$
175+
DECLARE
176+
rec RECORD;
177+
BEGIN
178+
FOR recIN (SELECTchild.relname,pg_constraint.consrc
179+
FROM pg_pathman_rels
180+
JOIN pg_classAS parentONparent.relname=pg_pathman_rels.relname
181+
JOIN pg_inheritsON inhparent=parent.relfilenode
182+
JOIN pg_constraintON conrelid= inhrelidAND contype='c'
183+
JOIN pg_classAS childONchild.relfilenode= inhrelid
184+
WHEREpg_pathman_rels.relname= p_parent)
185+
LOOP
186+
RAISE NOTICE'child %, condition %',rec.relname,rec.consrc;
187+
188+
EXECUTE format('WITH part_data AS (
189+
DELETE FROM ONLY %s WHERE %s RETURNING *)
190+
INSERT INTO %s SELECT * FROM part_data'
191+
, p_parent
192+
,rec.consrc
193+
,rec.relname);
194+
END LOOP;
195+
RETURN0;
196+
END
197+
$$ LANGUAGE plpgsql;
198+
199+
172200
-- CREATE OR REPLACE FUNCTION sample_rel_trigger_func()
173201
-- RETURNS TRIGGER AS $$
174202
-- DECLARE

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp