Make EXPLAIN generate a generic plan for a parameterized query - Mailing list pgsql-hackers

From Laurenz Albe
Subject Make EXPLAIN generate a generic plan for a parameterized query
Date
Msg-id 0a29b954b10b57f0d135fe12aa0909bd41883eb0.camel@cybertec.at
Whole thread Raw
Responses Re: Make EXPLAIN generate a generic plan for a parameterized query  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Today you get

test=> EXPLAIN SELECT * FROM tab WHERE col = $1;
ERROR:  there is no parameter $1

which makes sense.  Nonetheless, it would be great to get a generic plan
for such a query.  Sometimes you don't have the parameters (if you grab
the statement from "pg_stat_statements", or if it is from an error message
in the log, and you didn't enable "log_parameter_max_length_on_error").
Sometimes it is just very painful to substitute the 25 parameters from
the detail message.

With the attached patch you can get the following:

test=> SET plan_cache_mode = force_generic_plan;
SET
test=> EXPLAIN (COSTS OFF) SELECT * FROM pg_proc WHERE oid = $1;
                  QUERY PLAN                   
═══════════════════════════════════════════════
 Index Scan using pg_proc_oid_index on pg_proc
   Index Cond: (oid = $1)
(2 rows)

That's not the same as a full-fledged EXPLAIN (ANALYZE, BUFFERS),
but it can definitely be helpful.

I tied that behavior to the setting of "plan_cache_mode" where you
are guaranteed to get a generic plan; I couldn't think of a better way.

Yours,
Laurenz Albe

Attachment

pgsql-hackers by date:

Previous
From: jiye
Date:
Subject: Re:Re: Is there any plan to support online schem change in postgresql?
Next
From: Önder Kalacı
Date:
Subject: Re: [PATCH] Use indexes on the subscriber when REPLICA IDENTITY is full on the publisher