Skip to content

Commit

Permalink
[PGPRO-11556] Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Karina Litskevich committed Nov 26, 2024
1 parent a7df7f6 commit 35d1c74
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
25 changes: 13 additions & 12 deletions expected/array.out
Original file line number Diff line number Diff line change
Expand Up @@ -854,27 +854,28 @@ DROP INDEX idx_array;
/*
* Check ordering using distance operator
*
* The idea of the test:
* We want to check that index scan provides as correct ordering by distance
* 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
* 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.
* Adding another sort expression to ORDER BY may cause another plan that
* doesn't use ordering provided by index.
* That's why we use the query you see below. We substitute 'Infinity' distance
* value with -1 because 'Infinity' are printed differently in output in
* different PostgreSQL versions. We substitute arrays that have infinite
* distance with {-1} because their order is undefined and we wnat to determine
* the test output.
* 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 */
/*
* Check that plan of the query uses ordering provided by index scan
*/
EXPLAIN (COSTS OFF)
SELECT
CASE WHEN distance = 'Infinity' THEN '{-1}'
Expand Down
25 changes: 13 additions & 12 deletions expected/array_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -847,27 +847,28 @@ DROP INDEX idx_array;
/*
* Check ordering using distance operator
*
* The idea of the test:
* We want to check that index scan provides as correct ordering by distance
* 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
* 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.
* Adding another sort expression to ORDER BY may cause another plan that
* doesn't use ordering provided by index.
* That's why we use the query you see below. We substitute 'Infinity' distance
* value with -1 because 'Infinity' are printed differently in output in
* different PostgreSQL versions. We substitute arrays that have infinite
* distance with {-1} because their order is undefined and we wnat to determine
* the test output.
* 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 */
/*
* Check that plan of the query uses ordering provided by index scan
*/
EXPLAIN (COSTS OFF)
SELECT
CASE WHEN distance = 'Infinity' THEN '{-1}'
Expand Down
26 changes: 14 additions & 12 deletions sql/array.sql
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,19 @@ DROP INDEX idx_array;
/*
* Check ordering using distance operator
*
* The idea of the test:
* We want to check that index scan provides as correct ordering by distance
* 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
* 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.
* Adding another sort expression to ORDER BY may cause another plan that
* doesn't use ordering provided by index.
* That's why we use the query you see below. We substitute 'Infinity' distance
* value with -1 because 'Infinity' are printed differently in output in
* different PostgreSQL versions. We substitute arrays that have infinite
* distance with {-1} because their order is undefined and we wnat to determine
* the test output.
* 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 (
Expand All @@ -234,7 +233,10 @@ CREATE TABLE test_array_order (

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 */
/*
* Check that plan of the query uses ordering provided by index scan
*/

EXPLAIN (COSTS OFF)
SELECT
CASE WHEN distance = 'Infinity' THEN '{-1}'
Expand Down

0 comments on commit 35d1c74

Please sign in to comment.