Skip to content

Commit

Permalink
opt: add rule expectations for GenerateInvertedIndexScan tests
Browse files Browse the repository at this point in the history
Release note: None
mgartner committed Jan 26, 2021
1 parent 7c894ce commit 5f4f0d9
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions pkg/sql/opt/xform/testdata/rules/select
Original file line number Diff line number Diff line change
@@ -1663,7 +1663,7 @@ project
# --------------------------------------------------

# Query only the primary key with no remaining filter.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM b WHERE j @> '{"a": "b"}'
----
project
@@ -1676,7 +1676,7 @@ project
│ └── spans: ["7a\x00\x01\x12b\x00\x01", "7a\x00\x01\x12b\x00\x01"]
└── key: (1)

memo
memo expect=GenerateInvertedIndexScans
SELECT k FROM b WHERE j @> '{"a": "b"}'
----
memo (optimized, ~7KB, required=[presentation: k:1])
@@ -1703,7 +1703,7 @@ memo (optimized, ~7KB, required=[presentation: k:1])
└── G9: (const '{"a": "b"}')

# Query requiring an index join with no remaining filter.
opt
opt expect=GenerateInvertedIndexScans
SELECT u, k FROM b WHERE j @> '{"a": "b"}'
----
project
@@ -1722,7 +1722,7 @@ project
│ └── spans: ["7a\x00\x01\x12b\x00\x01", "7a\x00\x01\x12b\x00\x01"]
└── key: (1)

opt
opt expect=GenerateInvertedIndexScans
SELECT j, k FROM b WHERE j @> '{"a": "b"}'
----
index-join b
@@ -1736,7 +1736,7 @@ index-join b
│ └── spans: ["7a\x00\x01\x12b\x00\x01", "7a\x00\x01\x12b\x00\x01"]
└── key: (1)

opt
opt expect=GenerateInvertedIndexScans
SELECT * FROM b WHERE j @> '{"a": "b"}'
----
index-join b
@@ -1750,7 +1750,7 @@ index-join b
│ └── spans: ["7a\x00\x01\x12b\x00\x01", "7a\x00\x01\x12b\x00\x01"]
└── key: (1)

opt
opt expect=GenerateInvertedIndexScans
SELECT * FROM b WHERE j @> '2'
----
index-join b
@@ -1767,7 +1767,7 @@ index-join b
└── key: (1)

# Disjunction.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM b WHERE j @> '2' OR j @> '1'
----
project
@@ -1796,7 +1796,7 @@ project
└── fd: (1)-->(6)

# Disjunction with non-tight predicate.
opt
opt expect=GenerateInvertedIndexScans
SELECT * FROM b WHERE j @> '[[1, 2]]' OR j @> '[[3, 4]]'
----
select
@@ -1848,7 +1848,7 @@ select
└── filters
└── (j:4 @> '[[1, 2]]') OR (j:4 @> '[[3, 4]]') [outer=(4), immutable, constraints=(/4: (/NULL - ])]

opt
opt expect=GenerateInvertedIndexScans
SELECT * FROM b WHERE j @> '[{}]'
----
index-join b
@@ -1873,7 +1873,7 @@ index-join b
├── key: (1)
└── fd: (1)-->(6)

opt
opt expect=GenerateInvertedIndexScans
SELECT * FROM b WHERE j @> '{"a": {}}'
----
index-join b
@@ -1898,7 +1898,7 @@ index-join b
├── key: (1)
└── fd: (1)-->(6)

opt
opt expect=GenerateInvertedIndexScans
SELECT * FROM b WHERE j @> '{"a": []}'
----
index-join b
@@ -1923,7 +1923,7 @@ index-join b
├── key: (1)
└── fd: (1)-->(6)

opt
opt expect=GenerateInvertedIndexScans
SELECT * FROM b WHERE j @> '{"a":[[{"b":{"c":[{"d":"e"}]}}]]}'
----
index-join b
@@ -1938,7 +1938,7 @@ index-join b
└── key: (1)

# GenerateInvertedIndexScans propagates row-level locking information.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM b WHERE j @> '{"a": "b"}' FOR UPDATE
----
project
@@ -1954,7 +1954,7 @@ project
└── key: (1)

# Tests for array inverted indexes.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM c WHERE a @> ARRAY[1]
----
project
@@ -1968,7 +1968,7 @@ project
└── key: (1)

# Disjunction.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM c WHERE a @> ARRAY[1] OR a @> ARRAY[2]
----
project
@@ -1988,7 +1988,7 @@ project
├── key: (1)
└── fd: (1)-->(5)

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM c WHERE a @> ARRAY[]::INT[]
----
project
@@ -2008,7 +2008,7 @@ project
├── key: (1)
└── fd: (1)-->(5)

opt
opt expect-not=GenerateInvertedIndexScans
SELECT k FROM c WHERE a IS NULL
----
project
@@ -2121,7 +2121,7 @@ CREATE INVERTED INDEX a_inv_idx ON c (a)
----

# Tests for geospatial constrained scans.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE ST_Intersects('SRID=4326;POINT(-43.23456 72.4567772)'::geography, geog)
----
project
@@ -2161,7 +2161,7 @@ project
└── st_intersects('0101000020E61000009279E40F069E45C0BEE36FD63B1D5240', geog:4) [outer=(4), immutable, constraints=(/4: (/NULL - ])]

# Same test as above, but with commuted arguments.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE ST_Intersects(geog, 'SRID=4326;POINT(-43.23456 72.4567772)'::geography)
----
project
@@ -2200,7 +2200,7 @@ project
└── filters
└── st_intersects(geog:4, '0101000020E61000009279E40F069E45C0BEE36FD63B1D5240') [outer=(4), immutable, constraints=(/4: (/NULL - ])]

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE ST_CoveredBy('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'::geometry, geom)
----
project
@@ -2240,7 +2240,7 @@ project
└── st_coveredby('0103000000010000000500000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000', geom:3) [outer=(3), immutable, constraints=(/3: (/NULL - ])]

# Same test as above, but with commuted arguments.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE ST_CoveredBy(geom, 'POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'::geometry)
----
project
@@ -2273,7 +2273,7 @@ project
└── filters
└── st_coveredby(geom:3, '0103000000010000000500000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000') [outer=(3), immutable, constraints=(/3: (/NULL - ])]

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE ST_DWithin('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'::geometry, geom, 2)
----
project
@@ -2306,7 +2306,7 @@ project
└── filters
└── st_dwithin('0103000000010000000500000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000', geom:3, 2.0) [outer=(3), immutable, constraints=(/3: (/NULL - ])]

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE ST_DFullyWithin('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'::geometry, geom, 2)
----
project
@@ -2339,7 +2339,7 @@ project
└── filters
└── st_dfullywithin('0103000000010000000500000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000', geom:3, 2.0) [outer=(3), immutable, constraints=(/3: (/NULL - ])]

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE ST_DWithin('SRID=4326;POINT(-43.23456 72.4567772)'::geography, geog, 2000)
----
project
@@ -2392,7 +2392,7 @@ project
└── filters
└── st_dwithin('0101000020E61000009279E40F069E45C0BEE36FD63B1D5240', geog:4, 2000.0) [outer=(4), immutable, constraints=(/4: (/NULL - ])]

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE ST_DWithin('SRID=4326;POINT(-43.23456 72.4567772)'::geography, geog, 2000, false)
----
project
@@ -2446,7 +2446,7 @@ project
└── st_dwithin('0101000020E61000009279E40F069E45C0BEE36FD63B1D5240', geog:4, 2000.0, false) [outer=(4), immutable, constraints=(/4: (/NULL - ])]

# Test for ST_DWithinExclusive
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE ST_DWithinExclusive('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'::geometry, geom, 2)
----
project
@@ -2480,7 +2480,7 @@ project
└── st_dwithinexclusive('0103000000010000000500000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000', geom:3, 2.0) [outer=(3), immutable, constraints=(/3: (/NULL - ])]

# Commuted version of previous test.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE ST_DWithinExclusive(geom, 'POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'::geometry, 2)
----
project
@@ -2513,7 +2513,7 @@ project
└── filters
└── st_dwithinexclusive(geom:3, '0103000000010000000500000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000', 2.0) [outer=(3), immutable, constraints=(/3: (/NULL - ])]

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE ST_DFullyWithinExclusive('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'::geometry, geom, 2)
----
project
@@ -2549,7 +2549,7 @@ project
# Multiple geospatial functions.
# NB: the union spans for the following query are a subset of the spans. This is a
# consequence of how intersectSpanExpression does simplification.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g
WHERE ST_Covers('SRID=4326;POINT(-43.23456 72.4567772)'::geography, geog)
AND ST_CoveredBy('SRID=4326;POINT(-40.23456 70.4567772)'::geography, geog)
@@ -2590,7 +2590,7 @@ project
├── st_covers('0101000020E61000009279E40F069E45C0BEE36FD63B1D5240', geog:4) [outer=(4), immutable, constraints=(/4: (/NULL - ])]
└── st_coveredby('0101000020E61000009279E40F061E44C0BEE36FD63B9D5140', geog:4) [outer=(4), immutable, constraints=(/4: (/NULL - ])]

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g
WHERE ST_Covers('SRID=4326;POINT(-43.23456 72.4567772)'::geography, geog)
OR ST_CoveredBy('SRID=4326;POINT(-40.23456 70.4567772)'::geography, geog)
@@ -2627,7 +2627,7 @@ project
└── filters
└── st_covers('0101000020E61000009279E40F069E45C0BEE36FD63B1D5240', geog:4) OR st_coveredby('0101000020E61000009279E40F061E44C0BEE36FD63B9D5140', geog:4) [outer=(4), immutable, constraints=(/4: (/NULL - ])]

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g
WHERE ST_Covers('SRID=4326;POINT(-43.23456 72.4567772)'::geography, geog)
OR (ST_CoveredBy('SRID=4326;LINESTRING(-118.4079 33.9434, 2.5559 49.0083)'::geography, geog)
@@ -2695,7 +2695,7 @@ project
└── st_covers('0101000020E61000009279E40F069E45C0BEE36FD63B1D5240', geog:4) OR (st_coveredby('0102000020E61000000200000075029A081B9A5DC0F085C954C1F840406DC5FEB27B720440454772F90F814840', geog:4) AND st_coveredby('0101000020E610000058569A94821E46C07BC7DFAC773A4E40', geog:4)) [outer=(4), immutable, constraints=(/4: (/NULL - ])]

# Multiple geospatial functions on different indexes.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g
WHERE ST_Covers('SRID=4326;POINT(-43.23456 72.4567772)'::geography, geog)
AND ST_Overlaps('LINESTRING ( 0 0, 0 2 )'::geometry, geom)
@@ -2753,7 +2753,7 @@ project
└── filters
└── st_covers('0101000020E61000009279E40F069E45C0BEE36FD63B1D5240', geog:4) OR st_touches('0102000000020000000000000000000000000000000000000000000000000000000000000000000040', geom:3) [outer=(3,4), immutable]

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g
WHERE ST_Covers('SRID=4326;POINT(-43.23456 72.4567772)'::geography, geog)
OR (ST_Intersects('SRID=4326;POINT(-40.23456 70.4567772)'::geography, geog)
@@ -2792,7 +2792,7 @@ project
└── st_covers('0101000020E61000009279E40F069E45C0BEE36FD63B1D5240', geog:4) OR (st_intersects('0101000020E61000009279E40F061E44C0BEE36FD63B9D5140', geog:4) AND st_crosses('0102000000020000000000000000000000000000000000000000000000000000000000000000000040', geom:3)) [outer=(3,4), immutable, constraints=(/4: (/NULL - ])]

# Filters on other columns.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g
WHERE ST_Covers('SRID=4326;POINT(-43.23456 72.4567772)'::geography, geog)
AND v = 3 AND k > 100
@@ -2841,7 +2841,7 @@ project
└── v:2 = 3 [outer=(2), constraints=(/2: [/3 - /3]; tight), fd=()-->(2)]

# Bounding box operations.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE 'BOX(1 2, 3 4)'::box2d ~ geom
----
project
@@ -2878,7 +2878,7 @@ project
└── filters
└── 'BOX(1 2,3 4)' ~ geom:3 [outer=(3), immutable]

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE geom ~ 'BOX(1 2, 3 4)'::box2d
----
project
@@ -2915,7 +2915,7 @@ project
└── filters
└── geom:3 ~ 'BOX(1 2,3 4)' [outer=(3), immutable, constraints=(/3: (/NULL - ])]

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM g WHERE geom ~ 'MULTIPOINT((2.2 2.2), (3.0 3.0))'::geometry
----
project
@@ -2977,7 +2977,7 @@ exec-ddl
CREATE INVERTED INDEX idx ON pi (j) WHERE s = 'foo'
----

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM pi WHERE j @> '{"a": "b"}' AND s = 'foo'
----
project
@@ -3000,7 +3000,7 @@ exec-ddl
CREATE INVERTED INDEX idx ON pi (j) WHERE j @> '{"group": 1}'
----

opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM pi WHERE j @> '{"a": "b"}' AND j @> '{"group": 1}'
----
project
@@ -3023,7 +3023,7 @@ exec-ddl
CREATE INVERTED INDEX idx ON pi (j) WHERE s = 'foo'
----

opt
opt expect=GenerateInvertedIndexScans
SELECT * FROM pi WHERE j @> '{"a": "b"}' AND s = 'foo'
----
index-join pi
@@ -3047,7 +3047,7 @@ exec-ddl
CREATE INVERTED INDEX idx ON pi (j) WHERE s IN ('foo', 'bar')
----

opt
opt expect=GenerateInvertedIndexScans
SELECT * FROM pi WHERE j @> '{"a": "b"}' AND j @> '{"group": 1}' AND s = 'foo'
----
select
@@ -3098,7 +3098,7 @@ exec-ddl
CREATE INVERTED INDEX idx2 ON pi (j) WHERE s = 'bar'
----

memo
memo expect=GenerateInvertedIndexScans
SELECT * FROM pi WHERE j @> '{"a": "b"}' AND s = 'bar'
----
memo (optimized, ~10KB, required=[presentation: k:1,s:2,j:3])
@@ -3172,7 +3172,7 @@ DROP INDEX idx

# Check that we can generate constraints by recognizing computed column
# expressions.
opt
opt expect=GenerateInvertedIndexScans
SELECT k FROM computed WHERE (j->'foo') @> '{"a": "b"}'
----
project

0 comments on commit 5f4f0d9

Please sign in to comment.