Skip to content

Commit 385c76f

Browse files
committed
Add PROCOID, COLLOID, OPEROID translation
1 parent 057683c commit 385c76f

File tree

4 files changed

+81
-8
lines changed

4 files changed

+81
-8
lines changed

init.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ RETURNS VOID AS 'pg_execplan'
1111
LANGUAGE C;
1212

1313
CREATE OR REPLACE FUNCTION @extschema@.pg_exec_query_plan(filename TEXT)
14-
RETURNS VOID AS 'pg_execplan'
14+
RETURNS BOOL AS 'pg_execplan'
1515
LANGUAGE C;

pg_execplan.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "commands/extension.h"
1010
#include "commands/prepare.h"
1111
#include "executor/executor.h"
12+
#include "nodes/nodes.h"
1213
#include "nodes/plannodes.h"
1314
#include "tcop/pquery.h"
1415
#include "tcop/utility.h"
@@ -146,7 +147,7 @@ pg_exec_query_plan(PG_FUNCTION_ARGS)
146147
}
147148
PG_CATCH();
148149
{
149-
elog(INFO, "!!!BAD PLAN: %s", plan_string);
150+
elog(INFO, "BAD PLAN: %s", plan_string);
150151
PG_RE_THROW();
151152
}
152153
PG_END_TRY();
@@ -172,6 +173,8 @@ pg_exec_query_plan(PG_FUNCTION_ARGS)
172173
query_string,
173174
cplan->stmt_list,
174175
cplan);
176+
PG_TRY();
177+
{
175178
PortalStart(portal, paramLI, eflags, InvalidSnapshot);
176179
PortalSetResultFormat(portal, 0, &format);
177180
(void) PortalRun(portal,
@@ -180,12 +183,20 @@ pg_exec_query_plan(PG_FUNCTION_ARGS)
180183
receiver,
181184
receiver,
182185
query_string);
186+
}
187+
PG_CATCH();
188+
{
189+
elog(INFO, "BAD QUERY: %s", query_string);
190+
PG_RETURN_BOOL(false);
191+
}
192+
PG_END_TRY();
193+
183194
receiver->rDestroy(receiver);
184195
PortalDrop(portal, false);
185196
DropPreparedStatement(query_string, false);
186197

187198
if (EXPLAN_DEBUG_LEVEL > 0)
188199
elog(INFO, "query execution finished.\n");
189200

190-
PG_RETURN_VOID();
201+
PG_RETURN_BOOL(true);
191202
}

tests/create_objects.sql

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
CREATE SCHEMA tests;
2+
SET search_path = 'tests';
3+
4+
CREATE TYPE int42;
15
-- Make dummy I/O routines using the existing internal support for int4, text
26
CREATE FUNCTION int42_in(cstring)
37
RETURNS int42
@@ -17,4 +21,29 @@ CREATE TYPE int42 (
1721
passedbyvalue
1822
);
1923

20-
CREATE TABLE t1 (id int42);
24+
-- RELOID, TYPEOID
25+
CREATE TABLE tests.t1 (id int42);
26+
CREATE TABLE t2 (id int, payload TEXT, par1 INT);
27+
28+
CREATE FUNCTION select1(tid INT) RETURNS VOID AS $$
29+
BEGIN
30+
INSERT INTO tests.t2 (id, payload, par1) VALUES (1, 'qwe', 2);
31+
END;
32+
$$ LANGUAGE plpgsql;
33+
34+
-- COLLOID
35+
CREATE COLLATION test1 (locale = 'en_US.utf8');
36+
CREATE TABLE ttest1 (
37+
id serial,
38+
a text COLLATE test1,
39+
b text COLLATE test1
40+
);
41+
INSERT INTO ttest1 (a, b) VALUES ('one', 'one');
42+
INSERT INTO ttest1 (a, b) VALUES ('one', 'two');
43+
44+
-- OPEROID
45+
CREATE OPERATOR public.### (
46+
leftarg = numeric,
47+
rightarg = numeric,
48+
procedure = numeric_add
49+
);

tests/rpl.sh

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/bin/bash
22

3-
# Script for the plan passing between separate instances
3+
# This script to pass some plans between separate instances.
44
U=`whoami`
5+
export LC_ALL=C
6+
export LANGUAGE="en_US:en"
57

68
# Paths
79
PGINSTALL=`pwd`/tmp_install/
@@ -25,8 +27,8 @@ make -C contrib install > /dev/null
2527

2628
mkdir PGDATA_Master
2729
mkdir PGDATA_Slave
28-
initdb -D PGDATA_Master
29-
initdb -D PGDATA_Slave
30+
initdb -D PGDATA_Master -E UTF8 --locale=C
31+
initdb -D PGDATA_Slave -E UTF8 --locale=C
3032
echo "shared_preload_libraries = 'postgres_fdw, pg_execplan'" >> PGDATA_Master/postgresql.conf
3133
echo "shared_preload_libraries = 'postgres_fdw, pg_execplan'" >> PGDATA_Slave/postgresql.conf
3234

@@ -47,8 +49,39 @@ psql -p 5433 -c "DROP TABLE t0;"
4749
#create database objects for check of oid switching
4850
psql -p 5432 -f contrib/pg_execplan/tests/create_objects.sql
4951
psql -p 5433 -f contrib/pg_execplan/tests/create_objects.sql
52+
psql -p 5433 -c "SELECT current_schemas(true);"
5053

5154
# TEST ON RELOID and TYPEOID objects.
52-
psql -p 5432 -c "SELECT pg_store_query_plan('../test.txt', 'SELECT * FROM t1;');"
55+
psql -p 5432 -c "SELECT pg_store_query_plan('../test.txt', 'SELECT * FROM tests.t1;');"
56+
psql -p 5433 -c "SELECT pg_exec_query_plan('../test.txt');"
57+
58+
psql -p 5432 -c "SELECT pg_store_query_plan('../test.txt', 'SELECT tests.select1(42);');"
59+
psql -p 5433 -c "SELECT pg_exec_query_plan('../test.txt');"
60+
psql -p 5432 -c "SELECT pg_exec_query_plan('../test.txt');"
61+
62+
psql -p 5432 -c "SELECT * FROM tests.t2;"
63+
psql -p 5433 -c "SELECT * FROM tests.t2;"
64+
65+
# COLLOID ----------------------------------------------------------------------
66+
# Check on different oids
67+
psql -p 5432 -c "SELECT oid, * FROM pg_collation WHERE collname LIKE 'test%';"
68+
psql -p 5433 -c "SELECT oid, * FROM pg_collation WHERE collname LIKE 'test%';"
69+
70+
psql -p 5432 -c "SELECT pg_store_query_plan('../test.txt', 'SELECT max(id) FROM tests.ttest1 WHERE a < b COLLATE tests.test1');"
71+
psql -p 5433 -c "SELECT pg_exec_query_plan('../test.txt');"
72+
73+
# OPEROID ----------------------------------------------------------------------
74+
# Check on different oids
75+
psql -p 5432 -c "SELECT oid, oprname, oprnamespace FROM pg_operator WHERE oprname LIKE '###';"
76+
psql -p 5433 -c "SELECT oid, oprname, oprnamespace FROM pg_operator WHERE oprname LIKE '###';"
77+
78+
# Test
79+
psql -p 5432 -c "SELECT pg_store_query_plan('../test.txt', 'SELECT id ### 1 FROM tests.ttest1;');"
80+
psql -p 5433 -c "SELECT pg_exec_query_plan('../test.txt');"
81+
82+
psql -p 5433 -c "SELECT pg_store_query_plan('../test.txt', 'SELECT collname, nspname
83+
FROM pg_collation JOIN pg_namespace ON (collnamespace = pg_namespace.oid)
84+
WHERE collname LIKE ''test%''
85+
ORDER BY 1;');"
5386
psql -p 5433 -c "SELECT pg_exec_query_plan('../test.txt');"
5487

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy