Skip to content

Commit

Permalink
Merge remote-tracking branch 'rum_original/master' into PGPRO-9336
Browse files Browse the repository at this point in the history
 Conflicts:
	.travis.yml
	Makefile
  • Loading branch information
VadimMinigaliev committed Dec 28, 2024
2 parents 6ba9b0c + 8ca0f71 commit 3c7055c
Show file tree
Hide file tree
Showing 54 changed files with 689 additions and 237 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
os: linux

dist: bionic
dist: jammy

language: c

Expand All @@ -23,6 +23,8 @@ notifications:
on_failure: always

env:
- PG_VERSION=17
- PG_VERSION=17 LEVEL=hardcore
- PG_VERSION=16
- PG_VERSION=16 LEVEL=hardcore
- PG_VERSION=15
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RUM is released under the PostgreSQL License, a liberal Open Source license, similar to the BSD or MIT licenses.

Portions Copyright (c) 2015-2019, Postgres Professional
Portions Copyright (c) 2015-2024, Postgres Professional
Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
Portions Copyright (c) 1994, The Regents of the University of California

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ TAP_TESTS = 1

ISOLATION = predicate-rum predicate-rum-2
ISOLATION_OPTS = --load-extension=rum
EXTRA_CLEAN = pglist_tmp

ifdef USE_PGXS
PG_CONFIG = pg_config
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ Typical installation procedure may look like this:

> **Important:** Don't forget to set the `PG_CONFIG` variable in case you want to test `RUM` on a custom build of PostgreSQL. Read more [here](https://wiki.postgresql.org/wiki/Building_and_Installing_PostgreSQL_Extension_Modules).
## Tests

$ make check

This command runs:
- regression tests;
- isolation tests;
- tap tests.

One of the tap tests downloads a 1GB archive and then unpacks it
into a file weighing almost 3GB. It is disabled by default.

To run this test, you need to set an environment variable:

$ export PG_TEST_EXTRA=big_values

The way to turn it off again:

$ export -n PG_TEST_EXTRA

## Common operators and functions

The **rum** module provides next operators.
Expand Down
9 changes: 9 additions & 0 deletions expected/altorder.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* ------------------------------------
* NOTE: This test behaves differenly
* ------------------------------------
*
* altorder.out - test output for 64-bit systems and
* altorder_1.out - test output for 32-bit systems.
*
*/
CREATE TABLE atsts (id int, t tsvector, d timestamp);
\copy atsts from 'data/tsts.data'
-- PGPRO-2537: We need more data to test rumsort.c with logtape.c
Expand Down
9 changes: 9 additions & 0 deletions expected/altorder_1.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* ------------------------------------
* NOTE: This test behaves differenly
* ------------------------------------
*
* altorder.out - test output for 64-bit systems and
* altorder_1.out - test output for 32-bit systems.
*
*/
CREATE TABLE atsts (id int, t tsvector, d timestamp);
\copy atsts from 'data/tsts.data'
-- PGPRO-2537: We need more data to test rumsort.c with logtape.c
Expand Down
9 changes: 9 additions & 0 deletions expected/altorder_hash.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* ------------------------------------
* NOTE: This test behaves differenly
* ------------------------------------
*
* altorder_hash.out - test output for 64-bit systems and
* altorder_hash_1.out - test output for 32-bit systems.
*
*/
CREATE TABLE atstsh (id int, t tsvector, d timestamp);
\copy atstsh from 'data/tsts.data'
CREATE INDEX atstsh_idx ON atstsh USING rum (t rum_tsvector_hash_addon_ops, d)
Expand Down
9 changes: 9 additions & 0 deletions expected/altorder_hash_1.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* ------------------------------------
* NOTE: This test behaves differenly
* ------------------------------------
*
* altorder_hash.out - test output for 64-bit systems and
* altorder_hash_1.out - test output for 32-bit systems.
*
*/
CREATE TABLE atstsh (id int, t tsvector, d timestamp);
\copy atstsh from 'data/tsts.data'
CREATE INDEX atstsh_idx ON atstsh USING rum (t rum_tsvector_hash_addon_ops, d)
Expand Down
77 changes: 58 additions & 19 deletions expected/array.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* ------------------------------------
* NOTE: This test behaves differenly
* ------------------------------------
*
* array.out - test output for 64-bit systems and
* array_1.out - test output for 32-bit systems.
*
*/
set enable_seqscan=off;
set enable_sort=off;
/*
Expand Down Expand Up @@ -843,41 +852,71 @@ EXPLAIN (COSTS OFF) SELECT * FROM test_array WHERE i % '{}';
DROP INDEX idx_array;
/*
* Check ordering using distance operator
*
* We want to check that index scan provides us correct ordering by distance
* operator. File 'data/rum_array.data' contains two arrays that statisfy
* i @> '{23,20}' and have finite distance i <=> '{51}', and a bunch of arrays
* that statisfy i @> '{23,20}' and have infinite distance i <=> '{51}'.
*
* When ordering by distance the order of this bunch of arrays with infinite
* distance is not determined and may depend of PostgreSQL version and system.
* We don't add another sort expression to ORDER BY because that might cause
* the planner to avoid using the index. Instead, we replace arrays that have
* infinite distance with {-1} to unambiguously determine the test output.
*
* 'Infinity' is printed differently in the output in different PostgreSQL
* versions, so we replace it with -1.
*/
CREATE TABLE test_array_order (
i int2[]
);
\copy test_array_order(i) from 'data/rum_array.data';
CREATE INDEX idx_array_order ON test_array_order USING rum (i rum_anyarray_ops);
/*
* Check that plan of the query uses ordering provided by index scan
*/
EXPLAIN (COSTS OFF)
SELECT *, i <=> '{51}' from test_array_order WHERE i @> '{23,20}' order by i <=> '{51}';
QUERY PLAN
------------------------------------------------------
Index Scan using idx_array_order on test_array_order
Index Cond: (i @> '{23,20}'::smallint[])
Order By: (i <=> '{51}'::smallint[])
(3 rows)
SELECT
CASE WHEN distance = 'Infinity' THEN '{-1}'
ELSE i
END i,
CASE WHEN distance = 'Infinity' THEN -1
ELSE distance::numeric(18,14)
END distance
FROM
(SELECT *, (i <=> '{51}') AS distance
FROM test_array_order WHERE i @> '{23,20}' ORDER BY distance) t;
QUERY PLAN
------------------------------------------------------------
Subquery Scan on t
-> Index Scan using idx_array_order on test_array_order
Index Cond: (i @> '{23,20}'::smallint[])
Order By: (i <=> '{51}'::smallint[])
(4 rows)

SELECT i,
SELECT
CASE WHEN distance = 'Infinity' THEN '{-1}'
ELSE i
END i,
CASE WHEN distance = 'Infinity' THEN -1
ELSE distance::numeric(18,14)
END distance
FROM
(SELECT *, (i <=> '{51}') AS distance
FROM test_array_order WHERE i @> '{23,20}' ORDER BY i <=> '{51}') t;
FROM test_array_order WHERE i @> '{23,20}' ORDER BY distance) t;
i | distance
---------------------+------------------
{20,23,51} | 1.73205080756888
{33,51,20,77,23,65} | 2.44948974278318
{23,76,34,23,2,20} | -1
{20,60,45,23,29} | -1
{23,89,38,20,40,95} | -1
{23,20,72} | -1
{73,23,20} | -1
{6,97,20,89,23} | -1
{20,98,30,23,1,66} | -1
{57,23,39,46,50,20} | -1
{81,20,26,22,23} | -1
{18,23,10,90,15,20} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
(12 rows)

77 changes: 58 additions & 19 deletions expected/array_1.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* ------------------------------------
* NOTE: This test behaves differenly
* ------------------------------------
*
* array.out - test output for 64-bit systems and
* array_1.out - test output for 32-bit systems.
*
*/
set enable_seqscan=off;
set enable_sort=off;
/*
Expand Down Expand Up @@ -836,41 +845,71 @@ EXPLAIN (COSTS OFF) SELECT * FROM test_array WHERE i % '{}';
DROP INDEX idx_array;
/*
* Check ordering using distance operator
*
* We want to check that index scan provides us correct ordering by distance
* operator. File 'data/rum_array.data' contains two arrays that statisfy
* i @> '{23,20}' and have finite distance i <=> '{51}', and a bunch of arrays
* that statisfy i @> '{23,20}' and have infinite distance i <=> '{51}'.
*
* When ordering by distance the order of this bunch of arrays with infinite
* distance is not determined and may depend of PostgreSQL version and system.
* We don't add another sort expression to ORDER BY because that might cause
* the planner to avoid using the index. Instead, we replace arrays that have
* infinite distance with {-1} to unambiguously determine the test output.
*
* 'Infinity' is printed differently in the output in different PostgreSQL
* versions, so we replace it with -1.
*/
CREATE TABLE test_array_order (
i int2[]
);
\copy test_array_order(i) from 'data/rum_array.data';
CREATE INDEX idx_array_order ON test_array_order USING rum (i rum_anyarray_ops);
/*
* Check that plan of the query uses ordering provided by index scan
*/
EXPLAIN (COSTS OFF)
SELECT *, i <=> '{51}' from test_array_order WHERE i @> '{23,20}' order by i <=> '{51}';
QUERY PLAN
------------------------------------------------------
Index Scan using idx_array_order on test_array_order
Index Cond: (i @> '{23,20}'::smallint[])
Order By: (i <=> '{51}'::smallint[])
(3 rows)
SELECT
CASE WHEN distance = 'Infinity' THEN '{-1}'
ELSE i
END i,
CASE WHEN distance = 'Infinity' THEN -1
ELSE distance::numeric(18,14)
END distance
FROM
(SELECT *, (i <=> '{51}') AS distance
FROM test_array_order WHERE i @> '{23,20}' ORDER BY distance) t;
QUERY PLAN
------------------------------------------------------------
Subquery Scan on t
-> Index Scan using idx_array_order on test_array_order
Index Cond: (i @> '{23,20}'::smallint[])
Order By: (i <=> '{51}'::smallint[])
(4 rows)

SELECT i,
SELECT
CASE WHEN distance = 'Infinity' THEN '{-1}'
ELSE i
END i,
CASE WHEN distance = 'Infinity' THEN -1
ELSE distance::numeric(18,14)
END distance
FROM
(SELECT *, (i <=> '{51}') AS distance
FROM test_array_order WHERE i @> '{23,20}' ORDER BY i <=> '{51}') t;
FROM test_array_order WHERE i @> '{23,20}' ORDER BY distance) t;
i | distance
---------------------+------------------
{20,23,51} | 1.73205080756888
{33,51,20,77,23,65} | 2.44948974278318
{23,76,34,23,2,20} | -1
{20,60,45,23,29} | -1
{23,89,38,20,40,95} | -1
{23,20,72} | -1
{73,23,20} | -1
{6,97,20,89,23} | -1
{20,98,30,23,1,66} | -1
{57,23,39,46,50,20} | -1
{81,20,26,22,23} | -1
{18,23,10,90,15,20} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
{-1} | -1
(12 rows)

9 changes: 9 additions & 0 deletions expected/float8.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* ------------------------------------
* NOTE: This test behaves differenly
* ------------------------------------
*
* float8.out - test output for 64-bit systems and
* float8_1.out - test output for 32-bit systems.
*
*/
set enable_seqscan=off;
CREATE TABLE test_float8 (
i float8
Expand Down
9 changes: 9 additions & 0 deletions expected/float8_1.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* ------------------------------------
* NOTE: This test behaves differenly
* ------------------------------------
*
* float8.out - test output for 64-bit systems and
* float8_1.out - test output for 32-bit systems.
*
*/
set enable_seqscan=off;
CREATE TABLE test_float8 (
i float8
Expand Down
9 changes: 9 additions & 0 deletions expected/int8.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* ------------------------------------
* NOTE: This test behaves differenly
* ------------------------------------
*
* int8.out - test output for 64-bit systems and
* int8_1.out - test output for 32-bit systems.
*
*/
set enable_seqscan=off;
CREATE TABLE test_int8 (
i int8
Expand Down
9 changes: 9 additions & 0 deletions expected/int8_1.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* ------------------------------------
* NOTE: This test behaves differenly
* ------------------------------------
*
* int8.out - test output for 64-bit systems and
* int8_1.out - test output for 32-bit systems.
*
*/
set enable_seqscan=off;
CREATE TABLE test_int8 (
i int8
Expand Down
9 changes: 9 additions & 0 deletions expected/money.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* ------------------------------------
* NOTE: This test behaves differenly
* ------------------------------------
*
* money.out - test output for 64-bit systems and
* money_1.out - test output for 32-bit systems.
*
*/
set enable_seqscan=off;
CREATE TABLE test_money (
i money
Expand Down
9 changes: 9 additions & 0 deletions expected/money_1.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* ------------------------------------
* NOTE: This test behaves differenly
* ------------------------------------
*
* money.out - test output for 64-bit systems and
* money_1.out - test output for 32-bit systems.
*
*/
set enable_seqscan=off;
CREATE TABLE test_money (
i money
Expand Down
Loading

0 comments on commit 3c7055c

Please sign in to comment.