Skip to content

Commit e438656

Browse files
committed
update oracle code for pg commit
1 parent 86be8c4 commit e438656

41 files changed

Lines changed: 3976 additions & 69 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/backend/executor/functions.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ init_execution_state(SQLFunctionCachePtr fcache)
806806
fcache->func->rettupdesc,
807807
slot);
808808
else
809-
fcache->junkFilter = ExecInitJunkFilter(resulttlist, slot);
809+
fcache->junkFilter = ExecInitJunkFilter(resulttlist, false, slot);
810810
}
811811

812812
if (fcache->func->returnsTuple)
@@ -936,6 +936,7 @@ prepare_next_query(SQLFunctionHashEntry *func)
936936
CompleteCachedPlan(plansource,
937937
queryTree_list,
938938
NULL,
939+
&func->rettype,
939940
NULL,
940941
0,
941942
(ParserSetupHook) sql_fn_parser_setup,

src/backend/oracle_parser/ora_gram.y

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,6 +2842,8 @@ alter_table_cmd:
28422842
n->subtype = AT_AlterConstraint;
28432843
n->def = (Node *) c;
28442844
c->conname = $3;
2845+
if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
2846+
c->alterEnforceability = true;
28452847
if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
28462848
CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
28472849
c->alterDeferrability = true;
@@ -2850,7 +2852,10 @@ alter_table_cmd:
28502852
processCASbits($4, @4, "FOREIGN KEY",
28512853
&c->deferrable,
28522854
&c->initdeferred,
2853-
NULL, NULL, &c->noinherit, yyscanner);
2855+
&c->is_enforced,
2856+
NULL,
2857+
&c->noinherit,
2858+
yyscanner);
28542859
$$ = (Node *) n;
28552860
}
28562861
/* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
@@ -4582,7 +4587,7 @@ ConstraintElem:
45824587
n->fk_del_set_cols = ($10)->deleteAction->cols;
45834588
processCASbits($11, @11, "FOREIGN KEY",
45844589
&n->deferrable, &n->initdeferred,
4585-
NULL, &n->skip_validation, NULL,
4590+
&n->is_enforced, &n->skip_validation, NULL,
45864591
yyscanner);
45874592
n->initially_valid = !n->skip_validation;
45884593
$$ = (Node *) n;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Parsed test spec with 2 sessions
2+
3+
starting permutation: s2_vacuum s2_mod s1_explain s1_begin s1_prepare s1_fetch_1 s2_vacuum s1_fetch_all s1_commit
4+
step s2_vacuum:
5+
VACUUM (TRUNCATE false) ios_bitmap;
6+
7+
step s2_mod:
8+
DELETE FROM ios_bitmap WHERE a > 1;
9+
10+
step s1_explain:
11+
EXPlAIN (COSTS OFF) DECLARE foo NO SCROLL CURSOR FOR SELECT row_number() OVER () FROM ios_bitmap WHERE a > 0 or b > 0;
12+
13+
QUERY PLAN
14+
---------------------------------------------------
15+
WindowAgg
16+
Window: w1 AS (ROWS UNBOUNDED PRECEDING)
17+
-> Bitmap Heap Scan on ios_bitmap
18+
Recheck Cond: ((a > 0) OR (b > 0))
19+
-> BitmapOr
20+
-> Bitmap Index Scan on ios_bitmap_a
21+
Index Cond: (a > 0)
22+
-> Bitmap Index Scan on ios_bitmap_b
23+
Index Cond: (b > 0)
24+
(9 rows)
25+
26+
step s1_begin: BEGIN;
27+
step s1_prepare:
28+
DECLARE foo NO SCROLL CURSOR FOR SELECT row_number() OVER () FROM ios_bitmap WHERE a > 0 or b > 0;
29+
30+
step s1_fetch_1:
31+
FETCH FROM foo;
32+
33+
row_number
34+
----------
35+
1
36+
(1 row)
37+
38+
step s2_vacuum:
39+
VACUUM (TRUNCATE false) ios_bitmap;
40+
41+
step s1_fetch_all:
42+
FETCH ALL FROM foo;
43+
44+
row_number
45+
----------
46+
(0 rows)
47+
48+
step s1_commit: COMMIT;

src/oracle_test/isolation/isolation_schedule

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ test: partial-index
1717
test: two-ids
1818
test: multiple-row-versions
1919
test: index-only-scan
20+
test: index-only-bitmapscan
2021
test: predicate-lock-hot-tuple
2122
test: update-conflict-out
2223
test: deadlock-simple
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# In the past we supported index-only bitmap heapscans. However the
2+
# implementation was unsound, see
3+
# https://postgr.es/m/873c33c5-ef9e-41f6-80b2-2f5e11869f1c%40garret.ru
4+
#
5+
# This test reliably triggered the problem before we removed the
6+
# optimization. We keep the test around to make it less likely for a similar
7+
# problem to be re-introduced.
8+
9+
setup
10+
{
11+
-- by using a low fillfactor and a wide tuple we can get multiple blocks
12+
-- with just few rows
13+
CREATE TABLE ios_bitmap (a int NOT NULL, b int not null, pad char(1024) default '')
14+
WITH (AUTOVACUUM_ENABLED = false, FILLFACTOR = 10);
15+
16+
INSERT INTO ios_bitmap SELECT g.i, g.i FROM generate_series(1, 10) g(i);
17+
18+
CREATE INDEX ios_bitmap_a ON ios_bitmap(a);
19+
CREATE INDEX ios_bitmap_b ON ios_bitmap(b);
20+
}
21+
22+
teardown
23+
{
24+
DROP TABLE ios_bitmap;
25+
}
26+
27+
28+
session s1
29+
30+
setup
31+
{
32+
SET enable_seqscan = false;
33+
}
34+
35+
step s1_begin { BEGIN; }
36+
step s1_commit { COMMIT; }
37+
38+
39+
# The test query uses an or between two indexes to ensure make it more likely
40+
# to use a bitmap index scan
41+
#
42+
# The row_number() hack is a way to have something returned (isolationtester
43+
# doesn't display empty rows) while still allowing for the index-only scan
44+
# optimization in bitmap heap scans, which requires an empty targetlist.
45+
step s1_prepare
46+
{
47+
DECLARE foo NO SCROLL CURSOR FOR SELECT row_number() OVER () FROM ios_bitmap WHERE a > 0 or b > 0;
48+
}
49+
50+
step s1_explain
51+
{
52+
EXPlAIN (COSTS OFF) DECLARE foo NO SCROLL CURSOR FOR SELECT row_number() OVER () FROM ios_bitmap WHERE a > 0 or b > 0;
53+
}
54+
55+
step s1_fetch_1
56+
{
57+
FETCH FROM foo;
58+
}
59+
60+
step s1_fetch_all
61+
{
62+
FETCH ALL FROM foo;
63+
}
64+
65+
66+
session s2
67+
68+
# Don't delete row 1 so we have a row for the cursor to "rest" on.
69+
step s2_mod
70+
{
71+
DELETE FROM ios_bitmap WHERE a > 1;
72+
}
73+
74+
# Disable truncation, as otherwise we'll just wait for a timeout while trying
75+
# to acquire the lock
76+
step s2_vacuum
77+
{
78+
VACUUM (TRUNCATE false) ios_bitmap;
79+
}
80+
81+
permutation
82+
# Vacuum first, to ensure VM exists, otherwise the bitmapscan will consider
83+
# VM to be size 0, due to caching. Can't do that in setup because
84+
s2_vacuum
85+
86+
# Delete nearly all rows, to make issue visible
87+
s2_mod
88+
89+
# Verify that the appropriate plan is chosen
90+
s1_explain
91+
92+
# Create a cursor
93+
s1_begin
94+
s1_prepare
95+
96+
# Fetch one row from the cursor, that ensures the index scan portion is done
97+
# before the vacuum in the next step
98+
s1_fetch_1
99+
100+
# With the bug this vacuum would have marked pages as all-visible that the
101+
# scan in the next step then would have considered all-visible, despite all
102+
# rows from those pages having been removed.
103+
s2_vacuum
104+
105+
# If this returns any rows, the bug is present
106+
s1_fetch_all
107+
108+
s1_commit

src/oracle_test/modules/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SUBDIRS = \
1515
oauth_validator \
1616
plsample \
1717
spgist_name_ops \
18+
test_aio \
1819
test_bloomfilter \
1920
test_copy_callbacks \
2021
test_custom_rmgrs \

src/oracle_test/modules/libpq_pipeline/libpq_pipeline.c

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,17 @@ copy_connection(PGconn *conn)
207207
PQconninfoOption *opts = PQconninfo(conn);
208208
const char **keywords;
209209
const char **vals;
210-
int nopts = 1;
211-
int i = 0;
210+
int nopts = 0;
211+
int i;
212212

213213
for (PQconninfoOption *opt = opts; opt->keyword != NULL; ++opt)
214214
nopts++;
215+
nopts++; /* for the NULL terminator */
215216

216217
keywords = pg_malloc(sizeof(char *) * nopts);
217218
vals = pg_malloc(sizeof(char *) * nopts);
218219

220+
i = 0;
219221
for (PQconninfoOption *opt = opts; opt->keyword != NULL; ++opt)
220222
{
221223
if (opt->val)
@@ -1406,6 +1408,110 @@ test_prepared(PGconn *conn)
14061408
fprintf(stderr, "ok\n");
14071409
}
14081410

1411+
/*
1412+
* Test max_protocol_version options.
1413+
*/
1414+
static void
1415+
test_protocol_version(PGconn *conn)
1416+
{
1417+
const char **keywords;
1418+
const char **vals;
1419+
int nopts;
1420+
PQconninfoOption *opts = PQconninfo(conn);
1421+
int protocol_version;
1422+
int max_protocol_version_index;
1423+
int i;
1424+
1425+
/*
1426+
* Prepare keywords/vals arrays, copied from the existing connection, with
1427+
* an extra slot for 'max_protocol_version'.
1428+
*/
1429+
nopts = 0;
1430+
for (PQconninfoOption *opt = opts; opt->keyword != NULL; ++opt)
1431+
nopts++;
1432+
nopts++; /* max_protocol_version */
1433+
nopts++; /* NULL terminator */
1434+
1435+
keywords = pg_malloc0(sizeof(char *) * nopts);
1436+
vals = pg_malloc0(sizeof(char *) * nopts);
1437+
1438+
i = 0;
1439+
for (PQconninfoOption *opt = opts; opt->keyword != NULL; ++opt)
1440+
{
1441+
if (opt->val)
1442+
{
1443+
keywords[i] = opt->keyword;
1444+
vals[i] = opt->val;
1445+
i++;
1446+
}
1447+
}
1448+
1449+
max_protocol_version_index = i;
1450+
keywords[i] = "max_protocol_version"; /* value is filled in below */
1451+
i++;
1452+
keywords[i] = vals[i] = NULL;
1453+
1454+
/*
1455+
* Test max_protocol_version=3.0
1456+
*/
1457+
vals[max_protocol_version_index] = "3.0";
1458+
conn = PQconnectdbParams(keywords, vals, false);
1459+
1460+
if (PQstatus(conn) != CONNECTION_OK)
1461+
pg_fatal("Connection to database failed: %s",
1462+
PQerrorMessage(conn));
1463+
1464+
protocol_version = PQfullProtocolVersion(conn);
1465+
if (protocol_version != 30000)
1466+
pg_fatal("expected 30000, got %d", protocol_version);
1467+
1468+
PQfinish(conn);
1469+
1470+
/*
1471+
* Test max_protocol_version=3.1. It's not valid, we went straight from
1472+
* 3.0 to 3.2.
1473+
*/
1474+
vals[max_protocol_version_index] = "3.1";
1475+
conn = PQconnectdbParams(keywords, vals, false);
1476+
1477+
if (PQstatus(conn) != CONNECTION_BAD)
1478+
pg_fatal("Connecting with max_protocol_version 3.1 should have failed.");
1479+
1480+
PQfinish(conn);
1481+
1482+
/*
1483+
* Test max_protocol_version=3.2
1484+
*/
1485+
vals[max_protocol_version_index] = "3.2";
1486+
conn = PQconnectdbParams(keywords, vals, false);
1487+
1488+
if (PQstatus(conn) != CONNECTION_OK)
1489+
pg_fatal("Connection to database failed: %s",
1490+
PQerrorMessage(conn));
1491+
1492+
protocol_version = PQfullProtocolVersion(conn);
1493+
if (protocol_version != 30002)
1494+
pg_fatal("expected 30002, got %d", protocol_version);
1495+
1496+
PQfinish(conn);
1497+
1498+
/*
1499+
* Test max_protocol_version=latest. 'latest' currently means '3.2'.
1500+
*/
1501+
vals[max_protocol_version_index] = "latest";
1502+
conn = PQconnectdbParams(keywords, vals, false);
1503+
1504+
if (PQstatus(conn) != CONNECTION_OK)
1505+
pg_fatal("Connection to database failed: %s",
1506+
PQerrorMessage(conn));
1507+
1508+
protocol_version = PQfullProtocolVersion(conn);
1509+
if (protocol_version != 30002)
1510+
pg_fatal("expected 30002, got %d", protocol_version);
1511+
1512+
PQfinish(conn);
1513+
}
1514+
14091515
/* Notice processor: print notices, and count how many we got */
14101516
static void
14111517
notice_processor(void *arg, const char *message)

src/oracle_test/modules/libpq_pipeline/t/001_libpq_pipeline.pl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ BEGIN
4949
push @extraargs, "-t" => $traceout;
5050
}
5151

52-
# Execute the test
52+
# Execute the test using the latest protocol version.
5353
$node->command_ok(
5454
[
5555
'libpq_pipeline', @extraargs,
56-
$testname, $node->connstr('postgres')
56+
$testname, $node->connstr('postgres') . " max_protocol_version=latest"
5757
],
5858
"libpq_pipeline $testname");
5959

@@ -72,6 +72,14 @@ BEGIN
7272
}
7373
}
7474

75+
# There were changes to query cancellation in protocol version 3.2, so
76+
# test separately that it still works the old protocol version too.
77+
$node->command_ok(
78+
[
79+
'libpq_pipeline', 'cancel', $node->connstr('postgres') . " max_protocol_version=3.0"
80+
],
81+
"libpq_pipeline cancel with protocol 3.0");
82+
7583
$node->stop('fast');
7684

7785
done_testing();

src/oracle_test/modules/meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2022-2024, PostgreSQL Global Development Group
1+
# Copyright (c) 2022-2025, PostgreSQL Global Development Group
22

33
subdir('brin')
44
subdir('commit_ts')
@@ -13,6 +13,7 @@ subdir('oauth_validator')
1313
subdir('plsample')
1414
subdir('spgist_name_ops')
1515
subdir('ssl_passphrase_callback')
16+
subdir('test_aio')
1617
subdir('test_bloomfilter')
1718
subdir('test_copy_callbacks')
1819
subdir('test_custom_rmgrs')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generated subdirectories
2+
/tmp_check/

0 commit comments

Comments
 (0)