-> Seq Scan on t2 t_2
(7 rows)
+--No.14-1-1 plancache invalidation
+CREATE TABLE s1.tpc AS SELECT a FROM generate_series(0, 999) a;
+CREATE INDEX ON s1.tpc(a);
+PREPARE p1 AS SELECT * FROM s1.tpc WHERE a < 999;
+/*+ IndexScan(tpc) */PREPARE p2 AS SELECT * FROM s1.tpc WHERE a < 999;
+/*+ SeqScan(tpc) */PREPARE p3(int) AS SELECT * FROM s1.tpc WHERE a = $1;
+EXPLAIN EXECUTE p1;
+ QUERY PLAN
+------------------------------------------------------
+ Seq Scan on tpc (cost=0.00..17.50 rows=333 width=4)
+ Filter: (a < 999)
+(2 rows)
+
+EXPLAIN EXECUTE p2;
+LOG: pg_hint_plan:
+used hint:
+IndexScan(tpc)
+not used hint:
+duplication hint:
+error hint:
+
+ QUERY PLAN
+------------------------------------------------------------------------
+ Index Scan using tpc_a_idx on tpc (cost=0.28..34.10 rows=333 width=4)
+ Index Cond: (a < 999)
+(2 rows)
+
+EXPLAIN EXECUTE p3(500);
+LOG: pg_hint_plan:
+used hint:
+SeqScan(tpc)
+not used hint:
+duplication hint:
+error hint:
+
+ QUERY PLAN
+----------------------------------------------------
+ Seq Scan on tpc (cost=0.00..17.50 rows=5 width=4)
+ Filter: (a = 500)
+(2 rows)
+
+-- The DROP invalidates the plan caches
+DROP TABLE s1.tpc;
+EXPLAIN EXECUTE p1;
+ERROR: relation "s1.tpc" does not exist
+EXPLAIN EXECUTE p2;
+ERROR: relation "s1.tpc" does not exist
+EXPLAIN EXECUTE p3(500);
+ERROR: relation "s1.tpc" does not exist
+CREATE TABLE s1.tpc AS SELECT a FROM generate_series(0, 999) a;
+CREATE INDEX ON s1.tpc(a);
+EXPLAIN EXECUTE p1;
+ QUERY PLAN
+------------------------------------------------------
+ Seq Scan on tpc (cost=0.00..17.50 rows=333 width=4)
+ Filter: (a < 999)
+(2 rows)
+
+EXPLAIN EXECUTE p2;
+LOG: pg_hint_plan:
+used hint:
+IndexScan(tpc)
+not used hint:
+duplication hint:
+error hint:
+
+ QUERY PLAN
+------------------------------------------------------------------------
+ Index Scan using tpc_a_idx on tpc (cost=0.28..34.10 rows=333 width=4)
+ Index Cond: (a < 999)
+(2 rows)
+
+EXPLAIN EXECUTE p3(500);
+LOG: pg_hint_plan:
+used hint:
+SeqScan(tpc)
+not used hint:
+duplication hint:
+error hint:
+
+ QUERY PLAN
+----------------------------------------------------
+ Seq Scan on tpc (cost=0.00..17.50 rows=5 width=4)
+ Filter: (a = 500)
+(2 rows)
+
+DEALLOCATE p1;
+DEALLOCATE p2;
+DEALLOCATE p3;
+DROP TABLE s1.tpc;
PreparedStatement *entry;
entry = FetchPreparedStatement(stmt->name, true);
- p = entry->plansource->query_string;
- target_query = (Query *) linitial (entry->plansource->query_list);
+
+ if (entry->plansource->is_valid)
+ {
+ p = entry->plansource->query_string;
+ target_query = (Query *) linitial (entry->plansource->query_list);
+ }
+ else
+ {
+ /* igonre the hint for EXECUTE if invalidated */
+ p = NULL;
+ target_query = NULL;
+ }
}
/* JumbleQuery accespts only a non-utility Query */
- if (!IsA(target_query, Query) ||
- target_query->utilityStmt != NULL)
+ if (target_query &&
+ (!IsA(target_query, Query) ||
+ target_query->utilityStmt != NULL))
target_query = NULL;
if (jumblequery)
current_hint_str = get_hints_from_comment(query_str);
MemoryContextSwitchTo(oldcontext);
}
+ else
+ {
+ /*
+ * Failed to get query. We would be in fetching invalidated
+ * plancache. Try the next chance.
+ */
+ current_hint_retrieved = false;
+ }
if (debug_level > 1)
{
int save_nestlevel;
PlannedStmt *result;
HintState *hstate;
- const char *prev_hint_str;
+ const char *prev_hint_str = NULL;
/*
* Use standard planner if pg_hint_plan is disabled or current nesting
SELECT recall_planner() FROM s1.t1 t_1
JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
ORDER BY t_1.c1;
+
+--No.14-1-1 plancache invalidation
+CREATE TABLE s1.tpc AS SELECT a FROM generate_series(0, 999) a;
+CREATE INDEX ON s1.tpc(a);
+PREPARE p1 AS SELECT * FROM s1.tpc WHERE a < 999;
+/*+ IndexScan(tpc) */PREPARE p2 AS SELECT * FROM s1.tpc WHERE a < 999;
+/*+ SeqScan(tpc) */PREPARE p3(int) AS SELECT * FROM s1.tpc WHERE a = $1;
+EXPLAIN EXECUTE p1;
+EXPLAIN EXECUTE p2;
+EXPLAIN EXECUTE p3(500);
+-- The DROP invalidates the plan caches
+DROP TABLE s1.tpc;
+EXPLAIN EXECUTE p1;
+EXPLAIN EXECUTE p2;
+EXPLAIN EXECUTE p3(500);
+CREATE TABLE s1.tpc AS SELECT a FROM generate_series(0, 999) a;
+CREATE INDEX ON s1.tpc(a);
+EXPLAIN EXECUTE p1;
+EXPLAIN EXECUTE p2;
+EXPLAIN EXECUTE p3(500);
+DEALLOCATE p1;
+DEALLOCATE p2;
+DEALLOCATE p3;
+DROP TABLE s1.tpc;