Skip to content

Commit 825e570

Browse files
committed
Fix type mismatch in pg_show_plans.pid and level
This was causing segfaults on 32-bit Linux.
1 parent 6a17adc commit 825e570

File tree

6 files changed

+40
-19
lines changed

6 files changed

+40
-19
lines changed

expected/formats.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ select * from nest();
3131
| "Startup Cost": 0.25, +
3232
| "Total Cost": 10.25, +
3333
| "Plan Rows": 1000, +
34-
| "Plan Width": 40 +
34+
| "Plan Width": 36 +
3535
| } +
3636
| ]
3737
1 | [ +
@@ -44,7 +44,7 @@ select * from nest();
4444
| "Startup Cost": 0.00, +
4545
| "Total Cost": 12.50, +
4646
| "Plan Rows": 333, +
47-
| "Plan Width": 40, +
47+
| "Plan Width": 36, +
4848
| "Filter": "(level >= 0)" +
4949
| } +
5050
| ]
@@ -75,7 +75,7 @@ select * from nest();
7575
| Startup Cost: 0.25 +
7676
| Total Cost: 10.25 +
7777
| Plan Rows: 1000 +
78-
| Plan Width: 40
78+
| Plan Width: 36
7979
1 | Plan: +
8080
| Node Type: "Function Scan" +
8181
| Parallel Aware: false +
@@ -85,7 +85,7 @@ select * from nest();
8585
| Startup Cost: 0.00 +
8686
| Total Cost: 12.50 +
8787
| Plan Rows: 333 +
88-
| Plan Width: 40 +
88+
| Plan Width: 36 +
8989
| Filter: "(level >= 0)"
9090
(2 rows)
9191

@@ -115,7 +115,7 @@ select * from nest();
115115
| <Startup-Cost>0.25</Startup-Cost> +
116116
| <Total-Cost>10.25</Total-Cost> +
117117
| <Plan-Rows>1000</Plan-Rows> +
118-
| <Plan-Width>40</Plan-Width> +
118+
| <Plan-Width>36</Plan-Width> +
119119
| </Plan> +
120120
| </explain>
121121
1 | <explain xmlns="http://www.postgresql.org/2009/explain">+
@@ -128,7 +128,7 @@ select * from nest();
128128
| <Startup-Cost>0.00</Startup-Cost> +
129129
| <Total-Cost>12.50</Total-Cost> +
130130
| <Plan-Rows>333</Plan-Rows> +
131-
| <Plan-Width>40</Plan-Width> +
131+
| <Plan-Width>36</Plan-Width> +
132132
| <Filter>(level &gt;= 0)</Filter> +
133133
| </Plan> +
134134
| </explain>

expected/formats_1.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ select * from nest();
3030
| "Startup Cost": 0.25, +
3131
| "Total Cost": 10.25, +
3232
| "Plan Rows": 1000, +
33-
| "Plan Width": 40 +
33+
| "Plan Width": 36 +
3434
| } +
3535
| ]
3636
1 | [ +
@@ -42,7 +42,7 @@ select * from nest();
4242
| "Startup Cost": 0.00, +
4343
| "Total Cost": 12.50, +
4444
| "Plan Rows": 333, +
45-
| "Plan Width": 40, +
45+
| "Plan Width": 36, +
4646
| "Filter": "(level >= 0)" +
4747
| } +
4848
| ]
@@ -72,7 +72,7 @@ select * from nest();
7272
| Startup Cost: 0.25 +
7373
| Total Cost: 10.25 +
7474
| Plan Rows: 1000 +
75-
| Plan Width: 40
75+
| Plan Width: 36
7676
1 | Plan: +
7777
| Node Type: "Function Scan" +
7878
| Parallel Aware: false +
@@ -81,7 +81,7 @@ select * from nest();
8181
| Startup Cost: 0.00 +
8282
| Total Cost: 12.50 +
8383
| Plan Rows: 333 +
84-
| Plan Width: 40 +
84+
| Plan Width: 36 +
8585
| Filter: "(level >= 0)"
8686
(2 rows)
8787

@@ -110,7 +110,7 @@ select * from nest();
110110
| <Startup-Cost>0.25</Startup-Cost> +
111111
| <Total-Cost>10.25</Total-Cost> +
112112
| <Plan-Rows>1000</Plan-Rows> +
113-
| <Plan-Width>40</Plan-Width> +
113+
| <Plan-Width>36</Plan-Width> +
114114
| </Plan> +
115115
| </explain>
116116
1 | <explain xmlns="http://www.postgresql.org/2009/explain">+
@@ -122,7 +122,7 @@ select * from nest();
122122
| <Startup-Cost>0.00</Startup-Cost> +
123123
| <Total-Cost>12.50</Total-Cost> +
124124
| <Plan-Rows>333</Plan-Rows> +
125-
| <Plan-Width>40</Plan-Width> +
125+
| <Plan-Width>36</Plan-Width> +
126126
| <Filter>(level &gt;= 0)</Filter> +
127127
| </Plan> +
128128
| </explain>

expected/pg_show_plans.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ show pg_show_plans.max_plan_length;
1212
(1 row)
1313

1414
create function nest()
15-
returns table (level bigint, plan text)
15+
returns table (level int, plan text)
1616
language plpgsql
1717
as $$
1818
begin
@@ -31,14 +31,14 @@ show pg_show_plans.plan_format;
3131
select level, plan from pg_show_plans;
3232
level | plan
3333
-------+-----------------------------------------------------------------------
34-
0 | Function Scan on pg_show_plans (cost=0.00..10.00 rows=1000 width=40)
34+
0 | Function Scan on pg_show_plans (cost=0.00..10.00 rows=1000 width=36)
3535
(1 row)
3636

3737
select * from nest();
3838
level | plan
3939
-------+----------------------------------------------------------------------
40-
0 | Function Scan on nest (cost=0.25..10.25 rows=1000 width=40)
41-
1 | Function Scan on pg_show_plans (cost=0.00..12.50 rows=333 width=40)+
40+
0 | Function Scan on nest (cost=0.25..10.25 rows=1000 width=36)
41+
1 | Function Scan on pg_show_plans (cost=0.00..12.50 rows=333 width=36)+
4242
| Filter: (level >= 0)
4343
(2 rows)
4444

pg_show_plans--1.0--1.1.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
-- pid/level changed from int8 to int
2+
DROP VIEW pg_show_plans;
3+
DROP FUNCTION pg_show_plans;
4+
5+
CREATE FUNCTION pg_show_plans(
6+
OUT pid int,
7+
OUT level int,
8+
OUT userid oid,
9+
OUT dbid oid,
10+
OUT plan text
11+
)
12+
RETURNS SETOF record
13+
AS 'MODULE_PATHNAME'
14+
LANGUAGE C;
15+
16+
-- Register a view on the function for ease of use.
17+
CREATE VIEW pg_show_plans AS
18+
SELECT * FROM pg_show_plans();
19+
20+
GRANT SELECT ON pg_show_plans TO PUBLIC;
21+
122
CREATE FUNCTION pgsp_format_yaml()
223
RETURNS void
324
AS 'MODULE_PATHNAME'

pg_show_plans--1.1.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ AS 'MODULE_PATHNAME'
3535
LANGUAGE C;
3636

3737
CREATE FUNCTION pg_show_plans(
38-
OUT pid int8,
39-
OUT level int8,
38+
OUT pid int,
39+
OUT level int,
4040
OUT userid oid,
4141
OUT dbid oid,
4242
OUT plan text

sql/pg_show_plans.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ show pg_show_plans.is_enabled;
44
show pg_show_plans.max_plan_length;
55

66
create function nest()
7-
returns table (level bigint, plan text)
7+
returns table (level int, plan text)
88
language plpgsql
99
as $$
1010
begin

0 commit comments

Comments
 (0)