Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pg_stat_plans_explain can cause unexpected query invocation on multistatement query strings #39

Open
terrorobe opened this issue Apr 18, 2014 · 0 comments

Comments

@terrorobe
Copy link
Contributor

Example:

foo=# select * from pg_stat_plans where planid = 4291451842;
-[ RECORD 1 ]-------+-------------------------------------------------------------------
planid              | 4291451842
userid              | 16384
dbid                | 126346
query               | insert into test(foo) values(7); insert into test(foo) values(11);
had_our_search_path | t
from_our_database   | t
query_explainable   | t
calls               | 12
total_time          | 0.532
rows                | 12
shared_blks_hit     | 65
shared_blks_read    | 1
shared_blks_written | 0
local_blks_hit      | 0
local_blks_read     | 0
local_blks_written  | 0
temp_blks_read      | 0
temp_blks_written   | 0
blk_read_time       | 0
blk_write_time      | 0
last_startup_cost   | 0
last_total_cost     | 0.015

foo=# truncate table test;
TRUNCATE TABLE
foo=# select * from test;
(No rows)
foo=# select pg_stat_plans_explain(4291451842, 16384, 126346);
-[ RECORD 1 ]---------+-------------------------------------------------
pg_stat_plans_explain | Insert on test  (cost=0.00..0.01 rows=1 width=0)
                      |   ->  Result  (cost=0.00..0.01 rows=1 width=0)

foo=# select * from test;
-[ RECORD 1 ]
id  | 82
foo | 11

To reproduce:

Generate a multi-statement entry in pg_stat_plans, e.g. with python/psycopg2. Doesn't seem to work from within psql.

#!/usr/bin/env python
import psycopg2

conn = psycopg2.connect("dbname='foo'")
curs = conn.cursor()

query = 'insert into test(foo) values(7); insert into test(foo) values(11);'
curs.execute(query)
conn.commit()

pg_stat_plans_explain will execute everything after the first semicolon/query literal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant