BUG #8049: Incorrect results when using ORDER BY and query planner options

From: th(at)atsc(dot)nl
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #8049: Incorrect results when using ORDER BY and query planner options
Date: 2013-04-09 15:01:33
Message-ID: E1UPa3B-0004K0-PJ@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

The following bug has been logged on the website:

Bug reference: 8049
Logged by: Teun Hoogendoorn
Email address: th(at)atsc(dot)nl
PostgreSQL version: 9.2.4
Operating system: CentOS 6.3 final 64bit
Description:

Hi,

I've got a strange problem with a query that produces more results than
expected. I made
a reproducible example to illustrate the problem.

The following query should give only 1 result (instead of 2):

*****************************************************************

CREATE TABLE _bug_header
(
h_n integer,
CONSTRAINT _bug_header_unique UNIQUE (h_n)
);

CREATE TABLE _bug_line
(
h_n integer,
l_n integer
);

INSERT INTO _bug_header VALUES(1);
INSERT INTO _bug_line VALUES(NULL, 1);
INSERT INTO _bug_line VALUES(NULL, 2);

SET sort_mem TO 64; SET enable_seqscan TO 0; SET enable_hashjoin TO 0; SET
enable_mergejoin TO 0; SET enable_sort TO 1; SET enable_indexscan TO 1;
SELECT * FROM
(
SELECT (COALESCE(h_n || '/', '') || l_n)::text AS fault
FROM
(
SELECT _bug_header.h_n, _bug_line.l_n
FROM _bug_line
LEFT OUTER JOIN _bug_header on (_bug_line.h_n = _bug_header.h_n)
) AS tmp
) AS tmp2
WHERE (lower(fault) = E'1')
ORDER BY
lower(fault) -- Removing the ORDER BY shows 1 (ok) record instead of 2
(wrong)
OFFSET 0;

*****************************************************************

Thanks,

Teun Hoogendoorn

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kevin Grittner 2013-04-09 15:20:10 Re: BUG #8048: Text Search
Previous Message Christoph Berg 2013-04-09 11:59:25 Re: [HACKERS] Re: BUG #8043: 9.2.4 doesn't open WAL files from archive, only looks in pg_xlog

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2013-04-09 15:06:19 sql_drop event trigger vs buildfarm
Previous Message Tom Lane 2013-04-09 14:33:37 Re: MV patch broke users of ExplainOneQuery_hook