• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: Commit

firtst release


Commit MetaInfo

Revisionf6d7e285a2b74bc7ebe85fcb65f264f5b610cccb (tree)
Time2017-05-19 11:04:06
AuthorKyotaro Horiguchi <horiguchi.kyotaro@lab....>
CommiterKyotaro Horiguchi

Log Message

Fix a bug of target query retrieval

The previous patch leaves a bug that get_query_string returns a Query
that JumbleQuery doesn't accept. This fixes that bug.

Change Summary

Incremental Difference

--- a/pg_hint_plan.c
+++ b/pg_hint_plan.c
@@ -1670,8 +1670,6 @@ get_query_string(ParseState *pstate, Query *query, Query **jumblequery)
16701670 if (jumblequery != NULL)
16711671 *jumblequery = query;
16721672
1673- Assert(plpgsql_recurse_level == 0);
1674-
16751673 if (query->commandType == CMD_UTILITY)
16761674 {
16771675 Query *target_query = query;
@@ -1680,15 +1678,14 @@ get_query_string(ParseState *pstate, Query *query, Query **jumblequery)
16801678 if (IsA(query->utilityStmt, ExplainStmt))
16811679 {
16821680 ExplainStmt *stmt = (ExplainStmt *)(query->utilityStmt);
1681+
16831682 Assert(IsA(stmt->query, Query));
16841683 target_query = (Query *)stmt->query;
16851684
1685+ /* strip out the top-level query for further processing */
16861686 if (target_query->commandType == CMD_UTILITY &&
16871687 target_query->utilityStmt != NULL)
16881688 target_query = (Query *)target_query->utilityStmt;
1689-
1690- if (jumblequery)
1691- *jumblequery = target_query;
16921689 }
16931690
16941691 if (IsA(target_query, CreateTableAsStmt))
@@ -1699,21 +1696,18 @@ get_query_string(ParseState *pstate, Query *query, Query **jumblequery)
16991696 */
17001697 CreateTableAsStmt *stmt = (CreateTableAsStmt *) target_query;
17011698 PreparedStatement *entry;
1702- Query *ent_query;
1699+ Query *tmp_query;
17031700
17041701 Assert(IsA(stmt->query, Query));
1705- target_query = (Query *) stmt->query;
1702+ tmp_query = (Query *) stmt->query;
17061703
1707- if (target_query->commandType == CMD_UTILITY &&
1708- IsA(target_query->utilityStmt, ExecuteStmt))
1704+ if (tmp_query->commandType == CMD_UTILITY &&
1705+ IsA(tmp_query->utilityStmt, ExecuteStmt))
17091706 {
1710- ExecuteStmt *estmt = (ExecuteStmt *) target_query->utilityStmt;
1707+ ExecuteStmt *estmt = (ExecuteStmt *) tmp_query->utilityStmt;
17111708 entry = FetchPreparedStatement(estmt->name, true);
17121709 p = entry->plansource->query_string;
1713- ent_query = (Query *) linitial (entry->plansource->query_list);
1714- Assert(IsA(ent_query, Query));
1715- if (jumblequery)
1716- *jumblequery = ent_query;
1710+ target_query = (Query *) linitial (entry->plansource->query_list);
17171711 }
17181712 }
17191713 else
@@ -1725,15 +1719,19 @@ get_query_string(ParseState *pstate, Query *query, Query **jumblequery)
17251719 */
17261720 ExecuteStmt *stmt = (ExecuteStmt *)target_query;
17271721 PreparedStatement *entry;
1728- Query *ent_query;
17291722
17301723 entry = FetchPreparedStatement(stmt->name, true);
17311724 p = entry->plansource->query_string;
1732- ent_query = (Query *) linitial (entry->plansource->query_list);
1733- Assert(IsA(ent_query, Query));
1734- if (jumblequery)
1735- *jumblequery = ent_query;
1725+ target_query = (Query *) linitial (entry->plansource->query_list);
17361726 }
1727+
1728+ /* We don't accept other than a Query other than a CMD_UTILITY */
1729+ if (!IsA(target_query, Query) ||
1730+ target_query->commandType == CMD_UTILITY)
1731+ target_query = NULL;
1732+
1733+ if (jumblequery)
1734+ *jumblequery = target_query;
17371735 }
17381736 /* Return NULL if the pstate is not identical to the top-level query */
17391737 else if (strcmp(pstate->p_sourcetext, p) != 0)
Show on old repository browser