• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: 提交

firtst release


Commit MetaInfo

修訂904a4fcd793b1e2e4cf7c860f51383708ab21482 (tree)
時間2022-03-09 12:18:23
作者Kyotaro Horiguchi <horikyota.ntt@gmai...>
CommiterKyotaro Horiguchi

Log Message

Ignore non-existent prepared statement in get_query_string.

CREATE FUNCTION of SQL function uses post_parse_analyze_hook during
validation. If the function contained EXECUTE <prepared statement>,
not only that statement may be nonexistent, but also there's no need
of the query string at that point.

Since execution of nonexistent prepared statement ends with failure
sooner or later, we can safely ignore that.

Backpatch to pg_hint_plan10 that are before the core's EOL.

Change Summary

差異

--- a/expected/pg_hint_plan.out
+++ b/expected/pg_hint_plan.out
@@ -8426,6 +8426,12 @@ SELECT relname, seq_scan, idx_scan FROM pg_stat_user_tables WHERE schemaname = '
84268426 p1_c2 | 0 | 2
84278427 (2 rows)
84288428
8429+-- Make sure the reference to validly non-existent prepared statement
8430+-- doesn't harm
8431+CREATE FUNCTION ppf() RETURNS void AS $$
8432+PREPARE pp1 AS SELECT 1;
8433+EXECUTE pp1;
8434+$$ LANGUAGE sql;
84298435 -- Subqueries on inheritance tables under UNION
84308436 EXPLAIN (COSTS off) SELECT val FROM p1 WHERE val < 1000
84318437 UNION ALL
--- a/pg_hint_plan.c
+++ b/pg_hint_plan.c
@@ -1885,9 +1885,14 @@ get_query_string(ParseState *pstate, Query *query, Query **jumblequery)
18851885 ExecuteStmt *stmt = (ExecuteStmt *)target_query;
18861886 PreparedStatement *entry;
18871887
1888- entry = FetchPreparedStatement(stmt->name, true);
1888+ /*
1889+ * Silently ignore nonexistent prepared statements. This may happen
1890+ * for EXECUTE within a function definition. Otherwise the
1891+ * execution will fail anyway.
1892+ */
1893+ entry = FetchPreparedStatement(stmt->name, false);
18891894
1890- if (entry->plansource->is_valid)
1895+ if (entry && entry->plansource->is_valid)
18911896 {
18921897 p = entry->plansource->query_string;
18931898 target_query = (Query *) linitial (entry->plansource->query_list);
--- a/sql/pg_hint_plan.sql
+++ b/sql/pg_hint_plan.sql
@@ -1015,6 +1015,13 @@ SELECT pg_sleep(1);
10151015 -- the index scan happened while planning.
10161016 SELECT relname, seq_scan, idx_scan FROM pg_stat_user_tables WHERE schemaname = 'public' AND (relname = 'p1_c1' OR relname = 'p1_c2');
10171017
1018+-- Make sure the reference to validly non-existent prepared statement
1019+-- doesn't harm
1020+CREATE FUNCTION ppf() RETURNS void AS $$
1021+PREPARE pp1 AS SELECT 1;
1022+EXECUTE pp1;
1023+$$ LANGUAGE sql;
1024+
10181025 -- Subqueries on inheritance tables under UNION
10191026 EXPLAIN (COSTS off) SELECT val FROM p1 WHERE val < 1000
10201027 UNION ALL
Show on old repository browser