Skip to content

[PGPRO-11599] Fix wrong results returned when order_by_attach=TRUE. #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions expected/altorder.out
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,48 @@ SELECT id, d FROM atsts WHERE t @@ 'wr&q:*' AND d >= '2016-05-16 14:21:25' ORDE
506 | Sun May 22 21:21:22.326724 2016
(112 rows)

CREATE TABLE test_table (id bigint, folder bigint, time bigint, tsv tsvector);
CREATE INDEX test_idx ON test_table USING rum(folder, tsv rum_tsvector_addon_ops, time) with (attach = 'time', to = 'tsv', order_by_attach=TRUE);
INSERT INTO test_table (id, folder, time, tsv) VALUES (1, 10, 100, to_tsvector('wordA'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (2, 20, 200, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (3, 10, 300, to_tsvector('wordA'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (4, 20, 400, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (5, 20, 60, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (6, 10, 40, to_tsvector('wordA'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (7, 20, 50, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (8, 10, 30, to_tsvector('wordA'));
EXPLAIN (costs off)
SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint);
QUERY PLAN
--------------------------------------------------------------------------------
Index Scan using test_idx on test_table
Index Cond: ((folder = '10'::bigint) AND (tsv @@ to_tsquery('wordA'::text)))
(2 rows)

SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint);
id | folder | time | tsv
----+--------+------+-----------
8 | 10 | 30 | 'worda':1
6 | 10 | 40 | 'worda':1
1 | 10 | 100 | 'worda':1
3 | 10 | 300 | 'worda':1
(4 rows)

EXPLAIN (costs off)
SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint) ORDER BY time <=| 500::bigint;
QUERY PLAN
--------------------------------------------------------------------------------
Index Scan using test_idx on test_table
Index Cond: ((folder = '10'::bigint) AND (tsv @@ to_tsquery('wordA'::text)))
Order By: ("time" <=| '500'::bigint)
(3 rows)

SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint) ORDER BY time <=| 500::bigint;
id | folder | time | tsv
----+--------+------+-----------
3 | 10 | 300 | 'worda':1
1 | 10 | 100 | 'worda':1
6 | 10 | 40 | 'worda':1
8 | 10 | 30 | 'worda':1
(4 rows)

47 changes: 47 additions & 0 deletions expected/altorder_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -572,3 +572,50 @@ SELECT id, d FROM atsts WHERE t @@ 'wr&q:*' AND d >= '2016-05-16 14:21:25' ORDE
506 | Sun May 22 21:21:22.326724 2016
(112 rows)

CREATE TABLE test_table (id bigint, folder bigint, time bigint, tsv tsvector);
CREATE INDEX test_idx ON test_table USING rum(folder, tsv rum_tsvector_addon_ops, time) with (attach = 'time', to = 'tsv', order_by_attach=TRUE);
ERROR: doesn't support order index over pass-by-reference column
INSERT INTO test_table (id, folder, time, tsv) VALUES (1, 10, 100, to_tsvector('wordA'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (2, 20, 200, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (3, 10, 300, to_tsvector('wordA'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (4, 20, 400, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (5, 20, 60, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (6, 10, 40, to_tsvector('wordA'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (7, 20, 50, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (8, 10, 30, to_tsvector('wordA'));
EXPLAIN (costs off)
SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint);
QUERY PLAN
----------------------------------------------------------------------------
Seq Scan on test_table
Filter: ((folder = '10'::bigint) AND (tsv @@ to_tsquery('wordA'::text)))
(2 rows)

SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint);
id | folder | time | tsv
----+--------+------+-----------
1 | 10 | 100 | 'worda':1
3 | 10 | 300 | 'worda':1
6 | 10 | 40 | 'worda':1
8 | 10 | 30 | 'worda':1
(4 rows)

EXPLAIN (costs off)
SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint) ORDER BY time <=| 500::bigint;
QUERY PLAN
----------------------------------------------------------------------------------
Sort
Sort Key: (("time" <=| '500'::bigint))
-> Seq Scan on test_table
Filter: ((folder = '10'::bigint) AND (tsv @@ to_tsquery('wordA'::text)))
(4 rows)

SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint) ORDER BY time <=| 500::bigint;
id | folder | time | tsv
----+--------+------+-----------
3 | 10 | 300 | 'worda':1
1 | 10 | 100 | 'worda':1
6 | 10 | 40 | 'worda':1
8 | 10 | 30 | 'worda':1
(4 rows)

50 changes: 50 additions & 0 deletions expected/altorder_2.out
Original file line number Diff line number Diff line change
Expand Up @@ -596,3 +596,53 @@ SELECT id, d FROM atsts WHERE t @@ 'wr&q:*' AND d >= '2016-05-16 14:21:25' ORDE
506 | Sun May 22 21:21:22.326724 2016
(112 rows)

CREATE TABLE test_table (id bigint, folder bigint, time bigint, tsv tsvector);
CREATE INDEX test_idx ON test_table USING rum(folder, tsv rum_tsvector_addon_ops, time) with (attach = 'time', to = 'tsv', order_by_attach=TRUE);
ERROR: doesn't support order index over pass-by-reference column
INSERT INTO test_table (id, folder, time, tsv) VALUES (1, 10, 100, to_tsvector('wordA'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (2, 20, 200, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (3, 10, 300, to_tsvector('wordA'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (4, 20, 400, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (5, 20, 60, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (6, 10, 40, to_tsvector('wordA'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (7, 20, 50, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (8, 10, 30, to_tsvector('wordA'));
EXPLAIN (costs off)
SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint);
QUERY PLAN
----------------------------------------------------------------------------
Seq Scan on test_table
Disabled Nodes: 1
Filter: ((folder = '10'::bigint) AND (tsv @@ to_tsquery('wordA'::text)))
(3 rows)

SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint);
id | folder | time | tsv
----+--------+------+-----------
1 | 10 | 100 | 'worda':1
3 | 10 | 300 | 'worda':1
6 | 10 | 40 | 'worda':1
8 | 10 | 30 | 'worda':1
(4 rows)

EXPLAIN (costs off)
SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint) ORDER BY time <=| 500::bigint;
QUERY PLAN
----------------------------------------------------------------------------------
Sort
Disabled Nodes: 1
Sort Key: (("time" <=| '500'::bigint))
-> Seq Scan on test_table
Disabled Nodes: 1
Filter: ((folder = '10'::bigint) AND (tsv @@ to_tsquery('wordA'::text)))
(6 rows)

SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint) ORDER BY time <=| 500::bigint;
id | folder | time | tsv
----+--------+------+-----------
3 | 10 | 300 | 'worda':1
1 | 10 | 100 | 'worda':1
6 | 10 | 40 | 'worda':1
8 | 10 | 30 | 'worda':1
(4 rows)

21 changes: 21 additions & 0 deletions sql/altorder.sql
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,24 @@ SELECT id, d FROM atsts WHERE t @@ 'wr&qh' AND d >= '2016-05-16 14:21:25' ORDER
EXPLAIN (costs off)
SELECT id, d FROM atsts WHERE t @@ 'wr&q:*' AND d >= '2016-05-16 14:21:25' ORDER BY d;
SELECT id, d FROM atsts WHERE t @@ 'wr&q:*' AND d >= '2016-05-16 14:21:25' ORDER BY d;

CREATE TABLE test_table (id bigint, folder bigint, time bigint, tsv tsvector);
CREATE INDEX test_idx ON test_table USING rum(folder, tsv rum_tsvector_addon_ops, time) with (attach = 'time', to = 'tsv', order_by_attach=TRUE);

INSERT INTO test_table (id, folder, time, tsv) VALUES (1, 10, 100, to_tsvector('wordA'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (2, 20, 200, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (3, 10, 300, to_tsvector('wordA'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (4, 20, 400, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (5, 20, 60, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (6, 10, 40, to_tsvector('wordA'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (7, 20, 50, to_tsvector('wordB'));
INSERT INTO test_table (id, folder, time, tsv) VALUES (8, 10, 30, to_tsvector('wordA'));

EXPLAIN (costs off)
SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint);
SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint);

EXPLAIN (costs off)
SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint) ORDER BY time <=| 500::bigint;
SELECT * FROM test_table WHERE tsv @@ (to_tsquery('wordA')) AND (folder = 10::bigint) ORDER BY time <=| 500::bigint;

Loading
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