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

Commit8b3b05c

Browse files
committed
fix errors found by clang-analyzer, add special rule for CTEs (PostgreSQL 9.5)
1 parent6a6ee15 commit8b3b05c

File tree

5 files changed

+68
-6
lines changed

5 files changed

+68
-6
lines changed

‎expected/pathman_upd_del.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,21 @@ EXPLAIN (COSTS OFF) DELETE FROM test.tmp t USING test.range_rel r WHERE r.dt = '
118118
(8 rows)
119119

120120
DELETE FROM test.tmp t USING test.range_rel r WHERE r.dt = '2010-01-02' AND r.id = t.id;
121+
EXPLAIN (COSTS OFF) WITH q AS (SELECT * FROM test.range_rel r WHERE r.dt = '2010-01-02') DELETE FROM test.tmp USING q;
122+
QUERY PLAN
123+
----------------------------------------------------------------------------------------
124+
Delete on tmp
125+
CTE q
126+
-> Append
127+
-> Seq Scan on range_rel_1 r
128+
Filter: (dt = 'Sat Jan 02 00:00:00 2010'::timestamp without time zone)
129+
-> Nested Loop
130+
-> CTE Scan on q
131+
-> Materialize
132+
-> Seq Scan on tmp
133+
(9 rows)
134+
135+
WITH q AS (SELECT * FROM test.range_rel r WHERE r.dt = '2010-01-02') DELETE FROM test.tmp USING q;
121136
DROP SCHEMA test CASCADE;
122137
NOTICE: drop cascades to 15 other objects
123138
DROP EXTENSION pg_pathman CASCADE;

‎expected/pathman_upd_del_1.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ EXPLAIN (COSTS OFF) DELETE FROM test.tmp t USING test.range_rel r WHERE r.dt = '
120120
(10 rows)
121121

122122
DELETE FROM test.tmp t USING test.range_rel r WHERE r.dt = '2010-01-02' AND r.id = t.id;
123+
EXPLAIN (COSTS OFF) WITH q AS (SELECT * FROM test.range_rel r WHERE r.dt = '2010-01-02') DELETE FROM test.tmp USING q;
124+
QUERY PLAN
125+
----------------------------------------------------------------------------------------
126+
Delete on tmp
127+
CTE q
128+
-> Append
129+
-> Seq Scan on range_rel_1 r
130+
Filter: (dt = 'Sat Jan 02 00:00:00 2010'::timestamp without time zone)
131+
-> Nested Loop
132+
-> CTE Scan on q
133+
-> Materialize
134+
-> Seq Scan on tmp
135+
(9 rows)
136+
137+
WITH q AS (SELECT * FROM test.range_rel r WHERE r.dt = '2010-01-02') DELETE FROM test.tmp USING q;
123138
DROP SCHEMA test CASCADE;
124139
NOTICE: drop cascades to 15 other objects
125140
DROP EXTENSION pg_pathman CASCADE;

‎sql/pathman_upd_del.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ CREATE SCHEMA pathman;
55
CREATE EXTENSION pg_pathman SCHEMA pathman;
66
CREATESCHEMAtest;
77

8+
9+
810
SET enable_indexscan=ON;
911
SET enable_seqscan= OFF;
1012

@@ -46,6 +48,11 @@ DELETE FROM test.range_rel r USING test.tmp t WHERE r.dt = '2010-01-02' AND r.id
4648
EXPLAIN (COSTS OFF)DELETEFROMtest.tmp t USINGtest.range_rel rWHEREr.dt='2010-01-02'ANDr.id=t.id;
4749
DELETEFROMtest.tmp t USINGtest.range_rel rWHEREr.dt='2010-01-02'ANDr.id=t.id;
4850

51+
EXPLAIN (COSTS OFF) WITH qAS (SELECT*FROMtest.range_rel rWHEREr.dt='2010-01-02')DELETEFROMtest.tmp USING q;
52+
WITH qAS (SELECT*FROMtest.range_rel rWHEREr.dt='2010-01-02')DELETEFROMtest.tmp USING q;
53+
54+
55+
4956
DROPSCHEMA test CASCADE;
5057
DROP EXTENSION pg_pathman CASCADE;
5158
DROPSCHEMA pathman CASCADE;

‎src/hooks.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ pathman_join_pathlist_hook(PlannerInfo *root,
9595
if (!IsPathmanReady()|| !pg_pathman_enable_runtimeappend)
9696
return;
9797

98+
/* We should only consider base relations */
99+
if (innerrel->reloptkind!=RELOPT_BASEREL)
100+
return;
101+
98102
/* We shouldn't process tables with active children */
99-
if (inner_rte&&inner_rte->inh)
103+
if (inner_rte->inh)
100104
return;
101105

102106
/* We can't handle full or right outer joins */

‎src/planner_tree_modification.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ typedef struct
5252

5353
/* params for handle_modification_query() */
5454
ParamListInfoquery_params;
55+
SubLink*parent_sublink;
5556
}transform_query_cxt;
5657

5758

@@ -183,6 +184,20 @@ pathman_transform_query_walker(Node *node, void *context)
183184
if (node==NULL)
184185
return false;
185186

187+
elseif (IsA(node,SubLink))
188+
{
189+
transform_query_cxt*current_context=context,
190+
next_context;
191+
192+
/* Initialize next context for bottom subqueries */
193+
next_context=*current_context;
194+
next_context.parent_sublink= (SubLink*)node;
195+
196+
returnexpression_tree_walker(node,
197+
pathman_transform_query_walker,
198+
(void*)&next_context);
199+
}
200+
186201
elseif (IsA(node,Query))
187202
{
188203
Query*query= (Query*)node;
@@ -238,11 +253,17 @@ disable_standard_inheritance(Query *parse, transform_query_cxt *context)
238253
Indexcurrent_rti;/* current range table entry index */
239254

240255
#ifdefLEGACY_ROWMARKS_95
241-
/* Don't process non-topmost non-select queries */
242-
if (parse->commandType!=CMD_SELECT||
243-
TRANSFORM_CONTEXT_HAS_PARENT(context,UPDATE)||
244-
TRANSFORM_CONTEXT_HAS_PARENT(context,DELETE))
245-
return;
256+
/* Don't process non-SELECT queries */
257+
if (parse->commandType!=CMD_SELECT)
258+
return;
259+
260+
/* Don't process queries under UPDATE or DELETE (except for CTEs) */
261+
if ((TRANSFORM_CONTEXT_HAS_PARENT(context,UPDATE)||
262+
TRANSFORM_CONTEXT_HAS_PARENT(context,DELETE))&&
263+
(context->parent_sublink&&
264+
context->parent_sublink->subselect== (Node*)parse&&
265+
context->parent_sublink->subLinkType!=CTE_SUBLINK))
266+
return;
246267
#endif
247268

248269
/* Walk through RangeTblEntries list */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp