mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-09 08:10:09 +08:00
Repair recalculation failure for nested sub-SELECTs, per bug report from
Didier Moens. Bug is new in 7.4, and was caused by not updating everyplace I should've when replacing locParam markers by allParam. Add a regression test to catch related errors in future.
This commit is contained in:
parent
608b85a23c
commit
1697568d57
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.168 2004/04/07 18:17:24 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.169 2004/05/11 02:21:37 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -343,6 +343,9 @@ subquery_planner(Query *parse, double tuple_fraction)
|
||||
|
||||
plan->extParam = bms_add_members(plan->extParam,
|
||||
initplan->plan->extParam);
|
||||
/* allParam must include all members of extParam */
|
||||
plan->allParam = bms_add_members(plan->allParam,
|
||||
plan->extParam);
|
||||
initplan_cost += initplan->plan->total_cost;
|
||||
}
|
||||
|
||||
|
@ -201,3 +201,78 @@ select count(distinct ss.ten) from
|
||||
10
|
||||
(1 row)
|
||||
|
||||
--
|
||||
-- Test case to catch problems with multiply nested sub-SELECTs not getting
|
||||
-- recalculated properly. Per bug report from Didier Moens.
|
||||
--
|
||||
CREATE TABLE orderstest (
|
||||
approver_ref integer,
|
||||
po_ref integer,
|
||||
ordercancelled boolean
|
||||
);
|
||||
INSERT INTO orderstest VALUES (1, 1, false);
|
||||
INSERT INTO orderstest VALUES (66, 5, false);
|
||||
INSERT INTO orderstest VALUES (66, 6, false);
|
||||
INSERT INTO orderstest VALUES (66, 7, false);
|
||||
INSERT INTO orderstest VALUES (66, 1, true);
|
||||
INSERT INTO orderstest VALUES (66, 8, false);
|
||||
INSERT INTO orderstest VALUES (66, 1, false);
|
||||
INSERT INTO orderstest VALUES (77, 1, false);
|
||||
INSERT INTO orderstest VALUES (1, 1, false);
|
||||
INSERT INTO orderstest VALUES (66, 1, false);
|
||||
INSERT INTO orderstest VALUES (1, 1, false);
|
||||
CREATE VIEW orders_view AS
|
||||
SELECT *,
|
||||
(SELECT CASE
|
||||
WHEN ord.approver_ref=1 THEN '---' ELSE 'Approved'
|
||||
END) AS "Approved",
|
||||
(SELECT CASE
|
||||
WHEN ord.ordercancelled
|
||||
THEN 'Cancelled'
|
||||
ELSE
|
||||
(SELECT CASE
|
||||
WHEN ord.po_ref=1
|
||||
THEN
|
||||
(SELECT CASE
|
||||
WHEN ord.approver_ref=1
|
||||
THEN '---'
|
||||
ELSE 'Approved'
|
||||
END)
|
||||
ELSE 'PO'
|
||||
END)
|
||||
END) AS "Status",
|
||||
(CASE
|
||||
WHEN ord.ordercancelled
|
||||
THEN 'Cancelled'
|
||||
ELSE
|
||||
(CASE
|
||||
WHEN ord.po_ref=1
|
||||
THEN
|
||||
(CASE
|
||||
WHEN ord.approver_ref=1
|
||||
THEN '---'
|
||||
ELSE 'Approved'
|
||||
END)
|
||||
ELSE 'PO'
|
||||
END)
|
||||
END) AS "Status_OK"
|
||||
FROM orderstest ord;
|
||||
SELECT * FROM orders_view;
|
||||
approver_ref | po_ref | ordercancelled | Approved | Status | Status_OK
|
||||
--------------+--------+----------------+----------+-----------+-----------
|
||||
1 | 1 | f | --- | --- | ---
|
||||
66 | 5 | f | Approved | PO | PO
|
||||
66 | 6 | f | Approved | PO | PO
|
||||
66 | 7 | f | Approved | PO | PO
|
||||
66 | 1 | t | Approved | Cancelled | Cancelled
|
||||
66 | 8 | f | Approved | PO | PO
|
||||
66 | 1 | f | Approved | Approved | Approved
|
||||
77 | 1 | f | Approved | Approved | Approved
|
||||
1 | 1 | f | --- | --- | ---
|
||||
66 | 1 | f | Approved | Approved | Approved
|
||||
1 | 1 | f | --- | --- | ---
|
||||
(11 rows)
|
||||
|
||||
DROP TABLE orderstest cascade;
|
||||
NOTICE: drop cascades to rule _RETURN on view orders_view
|
||||
NOTICE: drop cascades to view orders_view
|
||||
|
@ -93,3 +93,67 @@ select count(*) from
|
||||
select count(distinct ss.ten) from
|
||||
(select ten from tenk1 a
|
||||
where unique1 IN (select distinct hundred from tenk1 b)) ss;
|
||||
|
||||
--
|
||||
-- Test case to catch problems with multiply nested sub-SELECTs not getting
|
||||
-- recalculated properly. Per bug report from Didier Moens.
|
||||
--
|
||||
|
||||
CREATE TABLE orderstest (
|
||||
approver_ref integer,
|
||||
po_ref integer,
|
||||
ordercancelled boolean
|
||||
);
|
||||
|
||||
INSERT INTO orderstest VALUES (1, 1, false);
|
||||
INSERT INTO orderstest VALUES (66, 5, false);
|
||||
INSERT INTO orderstest VALUES (66, 6, false);
|
||||
INSERT INTO orderstest VALUES (66, 7, false);
|
||||
INSERT INTO orderstest VALUES (66, 1, true);
|
||||
INSERT INTO orderstest VALUES (66, 8, false);
|
||||
INSERT INTO orderstest VALUES (66, 1, false);
|
||||
INSERT INTO orderstest VALUES (77, 1, false);
|
||||
INSERT INTO orderstest VALUES (1, 1, false);
|
||||
INSERT INTO orderstest VALUES (66, 1, false);
|
||||
INSERT INTO orderstest VALUES (1, 1, false);
|
||||
|
||||
CREATE VIEW orders_view AS
|
||||
SELECT *,
|
||||
(SELECT CASE
|
||||
WHEN ord.approver_ref=1 THEN '---' ELSE 'Approved'
|
||||
END) AS "Approved",
|
||||
(SELECT CASE
|
||||
WHEN ord.ordercancelled
|
||||
THEN 'Cancelled'
|
||||
ELSE
|
||||
(SELECT CASE
|
||||
WHEN ord.po_ref=1
|
||||
THEN
|
||||
(SELECT CASE
|
||||
WHEN ord.approver_ref=1
|
||||
THEN '---'
|
||||
ELSE 'Approved'
|
||||
END)
|
||||
ELSE 'PO'
|
||||
END)
|
||||
END) AS "Status",
|
||||
(CASE
|
||||
WHEN ord.ordercancelled
|
||||
THEN 'Cancelled'
|
||||
ELSE
|
||||
(CASE
|
||||
WHEN ord.po_ref=1
|
||||
THEN
|
||||
(CASE
|
||||
WHEN ord.approver_ref=1
|
||||
THEN '---'
|
||||
ELSE 'Approved'
|
||||
END)
|
||||
ELSE 'PO'
|
||||
END)
|
||||
END) AS "Status_OK"
|
||||
FROM orderstest ord;
|
||||
|
||||
SELECT * FROM orders_view;
|
||||
|
||||
DROP TABLE orderstest cascade;
|
||||
|
Loading…
Reference in New Issue
Block a user