Skip to content
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
11 changes: 5 additions & 6 deletions contrib/btree_gist/expected/cash_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ SELECT a, a <-> '21472.79' FROM moneytmp ORDER BY a <-> '21472.79' LIMIT 3;
QUERY PLAN
------------------------------------------------------------
Limit
-> Sort
Sort Key: ((a <-> '$21,472.79'::money))
-> Result
-> Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on moneytmp
Optimizer: GPORCA
-> Gather Motion 3:1 (slice1; segments: 3)
Merge Key: ((a <-> '$21,472.79'::money))
-> Limit
-> Index Only Scan using moneyidx on moneytmp
Order By: (a <-> '$21,472.79'::money)
(7 rows)

SELECT a, a <-> '21472.79' FROM moneytmp ORDER BY a <-> '21472.79' LIMIT 3;
Expand Down
7 changes: 3 additions & 4 deletions contrib/btree_gist/expected/date_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ SELECT a, a <-> '2001-02-13' FROM datetmp ORDER BY a <-> '2001-02-13' LIMIT 3;
Limit
-> Gather Motion 3:1 (slice1; segments: 3)
Merge Key: ((a <-> '02-13-2001'::date))
-> Sort
Sort Key: ((a <-> '02-13-2001'::date))
-> Seq Scan on datetmp
Optimizer: GPORCA
-> Limit
-> Index Only Scan using dateidx on datetmp
Order By: (a <-> '02-13-2001'::date)
(7 rows)

SELECT a, a <-> '2001-02-13' FROM datetmp ORDER BY a <-> '2001-02-13' LIMIT 3;
Expand Down
7 changes: 3 additions & 4 deletions contrib/btree_gist/expected/float4_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ SELECT a, a <-> '-179.0' FROM float4tmp ORDER BY a <-> '-179.0' LIMIT 3;
Limit
-> Gather Motion 3:1 (slice1; segments: 3)
Merge Key: ((a <-> '-179'::real))
-> Sort
Sort Key: ((a <-> '-179'::real))
-> Seq Scan on float4tmp
Optimizer: GPORCA
-> Limit
-> Index Only Scan using float4idx on float4tmp
Order By: (a <-> '-179'::real)
(7 rows)

SELECT a, a <-> '-179.0' FROM float4tmp ORDER BY a <-> '-179.0' LIMIT 3;
Expand Down
7 changes: 3 additions & 4 deletions contrib/btree_gist/expected/float8_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ SELECT a, a <-> '-1890.0' FROM float8tmp ORDER BY a <-> '-1890.0' LIMIT 3;
Limit
-> Gather Motion 3:1 (slice1; segments: 3)
Merge Key: ((a <-> '-1890'::double precision))
-> Sort
Sort Key: ((a <-> '-1890'::double precision))
-> Seq Scan on float8tmp
Optimizer: GPORCA
-> Limit
-> Index Only Scan using float8idx on float8tmp
Order By: (a <-> '-1890'::double precision)
(7 rows)

SELECT a, a <-> '-1890.0' FROM float8tmp ORDER BY a <-> '-1890.0' LIMIT 3;
Expand Down
7 changes: 3 additions & 4 deletions contrib/btree_gist/expected/int2_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ SELECT a, a <-> '237' FROM int2tmp ORDER BY a <-> '237' LIMIT 3;
Limit
-> Gather Motion 3:1 (slice1; segments: 3)
Merge Key: ((a <-> '237'::smallint))
-> Sort
Sort Key: ((a <-> '237'::smallint))
-> Seq Scan on int2tmp
Optimizer: GPORCA
-> Limit
-> Index Only Scan using int2idx on int2tmp
Order By: (a <-> '237'::smallint)
(7 rows)

SELECT a, a <-> '237' FROM int2tmp ORDER BY a <-> '237' LIMIT 3;
Expand Down
7 changes: 3 additions & 4 deletions contrib/btree_gist/expected/int4_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ SELECT a, a <-> '237' FROM int4tmp ORDER BY a <-> '237' LIMIT 3;
Limit
-> Gather Motion 3:1 (slice1; segments: 3)
Merge Key: ((a <-> 237))
-> Sort
Sort Key: ((a <-> 237))
-> Seq Scan on int4tmp
Optimizer: GPORCA
-> Limit
-> Index Only Scan using int4idx on int4tmp
Order By: (a <-> 237)
(7 rows)

SELECT a, a <-> '237' FROM int4tmp ORDER BY a <-> '237' LIMIT 3;
Expand Down
7 changes: 3 additions & 4 deletions contrib/btree_gist/expected/int8_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ SELECT a, a <-> '464571291354841' FROM int8tmp ORDER BY a <-> '464571291354841'
Limit
-> Gather Motion 3:1 (slice1; segments: 3)
Merge Key: ((a <-> '464571291354841'::bigint))
-> Sort
Sort Key: ((a <-> '464571291354841'::bigint))
-> Seq Scan on int8tmp
Optimizer: GPORCA
-> Limit
-> Index Only Scan using int8idx on int8tmp
Order By: (a <-> '464571291354841'::bigint)
(7 rows)

SELECT a, a <-> '464571291354841' FROM int8tmp ORDER BY a <-> '464571291354841' LIMIT 3;
Expand Down
24 changes: 12 additions & 12 deletions contrib/btree_gist/expected/interval_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ SELECT count(*) FROM intervaltmp WHERE a > '199 days 21:21:23'::interval;

EXPLAIN (COSTS OFF)
SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21:21:23' LIMIT 3;
QUERY PLAN
-----------------------------------------------------------------------------------
QUERY PLAN
---------------------------------------------------------------------------------------
Limit
-> Gather Motion 3:1 (slice1; segments: 3)
Merge Key: ((a <-> '@ 199 days 21 hours 21 mins 23 secs'::interval))
-> Sort
Sort Key: ((a <-> '@ 199 days 21 hours 21 mins 23 secs'::interval))
-> Seq Scan on intervaltmp
Optimizer: GPORCA
-> Limit
-> Index Only Scan using intervalidx on intervaltmp
Order By: (a <-> '@ 199 days 21 hours 21 mins 23 secs'::interval)
Optimizer: Postgres query optimizer
(7 rows)

SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21:21:23' LIMIT 3;
Expand All @@ -96,15 +96,15 @@ SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21
SET enable_indexonlyscan=off;
EXPLAIN (COSTS OFF)
SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21:21:23' LIMIT 3;
QUERY PLAN
-----------------------------------------------------------------------------------
QUERY PLAN
---------------------------------------------------------------------------------------
Limit
-> Gather Motion 3:1 (slice1; segments: 3)
Merge Key: ((a <-> '@ 199 days 21 hours 21 mins 23 secs'::interval))
-> Sort
Sort Key: ((a <-> '@ 199 days 21 hours 21 mins 23 secs'::interval))
-> Seq Scan on intervaltmp
Optimizer: GPORCA
-> Limit
-> Index Scan using intervalidx on intervaltmp
Order By: (a <-> '@ 199 days 21 hours 21 mins 23 secs'::interval)
Optimizer: Postgres query optimizer
(7 rows)

SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21:21:23' LIMIT 3;
Expand Down
7 changes: 3 additions & 4 deletions contrib/btree_gist/expected/time_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ SELECT a, a <-> '10:57:11' FROM timetmp ORDER BY a <-> '10:57:11' LIMIT 3;
Limit
-> Gather Motion 3:1 (slice1; segments: 3)
Merge Key: ((a <-> '10:57:11'::time without time zone))
-> Sort
Sort Key: ((a <-> '10:57:11'::time without time zone))
-> Seq Scan on timetmp
Optimizer: GPORCA
-> Limit
-> Index Only Scan using timeidx on timetmp
Order By: (a <-> '10:57:11'::time without time zone)
(7 rows)

SELECT a, a <-> '10:57:11' FROM timetmp ORDER BY a <-> '10:57:11' LIMIT 3;
Expand Down
7 changes: 3 additions & 4 deletions contrib/btree_gist/expected/timestamp_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ SELECT a, a <-> '2004-10-26 08:55:08' FROM timestamptmp ORDER BY a <-> '2004-10-
Limit
-> Gather Motion 3:1 (slice1; segments: 3)
Merge Key: ((a <-> 'Tue Oct 26 08:55:08 2004'::timestamp without time zone))
-> Sort
Sort Key: ((a <-> 'Tue Oct 26 08:55:08 2004'::timestamp without time zone))
-> Seq Scan on timestamptmp
Optimizer: GPORCA
-> Limit
-> Index Only Scan using timestampidx on timestamptmp
Order By: (a <-> 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
(7 rows)

SELECT a, a <-> '2004-10-26 08:55:08' FROM timestamptmp ORDER BY a <-> '2004-10-26 08:55:08' LIMIT 3;
Expand Down
7 changes: 3 additions & 4 deletions contrib/btree_gist/expected/timestamptz_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,9 @@ SELECT a, a <-> '2018-12-18 10:59:54 GMT+2' FROM timestamptztmp ORDER BY a <-> '
Limit
-> Gather Motion 3:1 (slice1; segments: 3)
Merge Key: ((a <-> 'Tue Dec 18 04:59:54 2018 PST'::timestamp with time zone))
-> Sort
Sort Key: ((a <-> 'Tue Dec 18 04:59:54 2018 PST'::timestamp with time zone))
-> Seq Scan on timestamptztmp
Optimizer: GPORCA
-> Limit
-> Index Only Scan using timestamptzidx on timestamptztmp
Order By: (a <-> 'Tue Dec 18 04:59:54 2018 PST'::timestamp with time zone)
(7 rows)

SELECT a, a <-> '2018-12-18 10:59:54 GMT+2' FROM timestamptztmp ORDER BY a <-> '2018-12-18 10:59:54 GMT+2' LIMIT 3;
Expand Down
23 changes: 13 additions & 10 deletions contrib/pg_trgm/expected/pg_trgm_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -2351,6 +2351,7 @@ select t <-> 'q0987wertyu0988', t from test_trgm order by t <-> 'q0987wertyu0988
-> Limit
-> Index Scan using trgm_idx on test_trgm
Order By: (t <-> 'q0987wertyu0988'::text)
Optimizer: Postgres query optimizer
(7 rows)

select t <-> 'q0987wertyu0988', t from test_trgm order by t <-> 'q0987wertyu0988' limit 2;
Expand Down Expand Up @@ -5003,8 +5004,8 @@ select * from test2 where t ~ '/\d+/-\d';
-- test = operator
explain (costs off)
select * from test2 where t = 'abcdef';
QUERY PLAN
------------------------------------------
QUERY PLAN
------------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
-> Bitmap Heap Scan on test2
Recheck Cond: (t = 'abcdef'::text)
Expand All @@ -5020,8 +5021,8 @@ select * from test2 where t = 'abcdef';

explain (costs off)
select * from test2 where t = '%line%';
QUERY PLAN
------------------------------------------
QUERY PLAN
------------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
-> Bitmap Heap Scan on test2
Recheck Cond: (t = '%line%'::text)
Expand Down Expand Up @@ -5311,14 +5312,15 @@ select * from test2 where t ~ '/\d+/-\d';
-- test = operator
explain (costs off)
select * from test2 where t = 'abcdef';
QUERY PLAN
------------------------------------------
QUERY PLAN
-------------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
-> Bitmap Heap Scan on test2
Recheck Cond: (t = 'abcdef'::text)
-> Bitmap Index Scan on test2_idx_gist
Index Cond: (t = 'abcdef'::text)
(2 rows)
Optimizer: Postgres query optimizer
(6 rows)

select * from test2 where t = 'abcdef';
t
Expand All @@ -5328,13 +5330,14 @@ select * from test2 where t = 'abcdef';

explain (costs off)
select * from test2 where t = '%line%';
QUERY PLAN
------------------------------------------
QUERY PLAN
-------------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
-> Bitmap Heap Scan on test2
Recheck Cond: (t = '%line%'::text)
-> Bitmap Index Scan on test2_idx_gist
Index Cond: (t = '%line%'::text)
Optimizer: Postgres query optimizer
(6 rows)

select * from test2 where t = '%line%';
Expand Down Expand Up @@ -5423,7 +5426,7 @@ SELECT DISTINCT city, similarity(city, 'Warsaw'), show_limit()
-> Index Scan using restaurants_city_idx on restaurants
Index Cond: (city % 'Warsaw'::text)
Filter: (city % 'Warsaw'::text)
Optimizer: Pivotal Optimizer (GPORCA)
Optimizer: GPORCA
(9 rows)

SELECT set_limit(0.3);
Expand Down
11 changes: 11 additions & 0 deletions src/backend/gpopt/gpdbwrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2012,6 +2012,17 @@ gpdb::CheckCollation(Node *node)
return -1;
}

bool
gpdb::HasOrderByOrderingOp(Query *query)
{
GP_WRAP_START;
{
return has_orderby_ordering_op(query);
}
GP_WRAP_END;
return false;
}

Node *
gpdb::CoerceToCommonType(ParseState *pstate, Node *node, Oid target_type,
const char *context)
Expand Down
9 changes: 9 additions & 0 deletions src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,15 @@ CTranslatorQueryToDXL::CheckUnsupportedNodeTypes(Query *query)
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature,
GPOS_WSZ_LIT("Non-default collation"));
}

// ORCA does not support amcanorderbyop (KNN ordered index scans).
// Fall back to the PostgreSQL planner for queries whose ORDER BY
// contains an ordering operator (e.g., <-> for distance).
if (gpdb::HasOrderByOrderingOp(query))
{
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature,
GPOS_WSZ_LIT("ORDER BY with ordering operator (amcanorderbyop)"));
}
}

//---------------------------------------------------------------------------
Expand Down
Loading
Loading