• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: コミット

firtst release


コミットメタ情報

リビジョン2afb4325137f19f551d81f813d98b2a6fd2998ac (tree)
日時2017-05-19 10:48:49
作者Kyotaro Horiguchi <horiguchi.kyotaro@lab....>
コミッターKyotaro Horiguchi

ログメッセージ

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.

変更サマリ

差分

--- a/pg_hint_plan.c
+++ b/pg_hint_plan.c
@@ -1657,8 +1657,6 @@ get_query_string(ParseState *pstate, Query *query, Query **jumblequery)
16571657 if (jumblequery != NULL)
16581658 *jumblequery = query;
16591659
1660- Assert(plpgsql_recurse_level == 0);
1661-
16621660 if (query->commandType == CMD_UTILITY)
16631661 {
16641662 Query *target_query = query;
@@ -1667,15 +1665,14 @@ get_query_string(ParseState *pstate, Query *query, Query **jumblequery)
16671665 if (IsA(query->utilityStmt, ExplainStmt))
16681666 {
16691667 ExplainStmt *stmt = (ExplainStmt *)(query->utilityStmt);
1668+
16701669 Assert(IsA(stmt->query, Query));
16711670 target_query = (Query *)stmt->query;
16721671
1672+ /* strip out the top-level query for further processing */
16731673 if (target_query->commandType == CMD_UTILITY &&
16741674 target_query->utilityStmt != NULL)
16751675 target_query = (Query *)target_query->utilityStmt;
1676-
1677- if (jumblequery)
1678- *jumblequery = target_query;
16791676 }
16801677
16811678 if (IsA(target_query, CreateTableAsStmt))
@@ -1686,21 +1683,18 @@ get_query_string(ParseState *pstate, Query *query, Query **jumblequery)
16861683 */
16871684 CreateTableAsStmt *stmt = (CreateTableAsStmt *) target_query;
16881685 PreparedStatement *entry;
1689- Query *ent_query;
1686+ Query *tmp_query;
16901687
16911688 Assert(IsA(stmt->query, Query));
1692- target_query = (Query *) stmt->query;
1689+ tmp_query = (Query *) stmt->query;
16931690
1694- if (target_query->commandType == CMD_UTILITY &&
1695- IsA(target_query->utilityStmt, ExecuteStmt))
1691+ if (tmp_query->commandType == CMD_UTILITY &&
1692+ IsA(tmp_query->utilityStmt, ExecuteStmt))
16961693 {
1697- ExecuteStmt *estmt = (ExecuteStmt *) target_query->utilityStmt;
1694+ ExecuteStmt *estmt = (ExecuteStmt *) tmp_query->utilityStmt;
16981695 entry = FetchPreparedStatement(estmt->name, true);
16991696 p = entry->plansource->query_string;
1700- ent_query = (Query *) linitial (entry->plansource->query_list);
1701- Assert(IsA(ent_query, Query));
1702- if (jumblequery)
1703- *jumblequery = ent_query;
1697+ target_query = (Query *) linitial (entry->plansource->query_list);
17041698 }
17051699 }
17061700 else
@@ -1712,15 +1706,19 @@ get_query_string(ParseState *pstate, Query *query, Query **jumblequery)
17121706 */
17131707 ExecuteStmt *stmt = (ExecuteStmt *)target_query;
17141708 PreparedStatement *entry;
1715- Query *ent_query;
17161709
17171710 entry = FetchPreparedStatement(stmt->name, true);
17181711 p = entry->plansource->query_string;
1719- ent_query = (Query *) linitial (entry->plansource->query_list);
1720- Assert(IsA(ent_query, Query));
1721- if (jumblequery)
1722- *jumblequery = ent_query;
1712+ target_query = (Query *) linitial (entry->plansource->query_list);
17231713 }
1714+
1715+ /* We don't accept other than a Query other than a CMD_UTILITY */
1716+ if (!IsA(target_query, Query) ||
1717+ target_query->commandType == CMD_UTILITY)
1718+ target_query = NULL;
1719+
1720+ if (jumblequery)
1721+ *jumblequery = target_query;
17241722 }
17251723 /* Return NULL if the pstate is not identical to the top-level query */
17261724 else if (strcmp(pstate->p_sourcetext, p) != 0)
旧リポジトリブラウザで表示