forked from babelfish-for-postgresql/babelfish_extensions
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sort operators for MAX/MIN of Babelfish datatypes (babelfish-for-…
…postgresql#1989) Previously, the MAX/MIN aggregation with index cannot be correctly optimized into LIMIT 1 + index scan. This affects most of existing Babelfish-defined datatypes. This commit fixes this issue by adding corresponding sort operators to the MAX/MIN aggregation functions. Task: BABEL-4311 Signed-off-by: Xiaohui Fanhe <[email protected]>
- Loading branch information
Showing
34 changed files
with
1,207 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
contrib/babelfishpg_common/sql/upgrades/babelfish_common_helper--3.2.0--3.3.0.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,126 @@ | ||
------------------------------------------------------------------------------ | ||
---- Include changes related to other datatypes except spatial types here ---- | ||
------------------------------------------------------------------------------ | ||
|
||
-- complain if script is sourced in psql, rather than via ALTER EXTENSION | ||
\echo Use "ALTER EXTENSION ""babelfishpg_common"" UPDATE TO "3.3.0"" to load this file. \quit | ||
|
||
SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false); | ||
|
||
-- Add SORTOP for aggregations | ||
-- bpchar | ||
CREATE OR REPLACE AGGREGATE sys.max(sys.BPCHAR) | ||
( | ||
sfunc = sys.bpchar_larger, | ||
stype = sys.bpchar, | ||
combinefunc = sys.bpchar_larger, | ||
sortop = >, | ||
parallel = safe | ||
); | ||
|
||
CREATE OR REPLACE AGGREGATE sys.min(sys.BPCHAR) | ||
( | ||
sfunc = sys.bpchar_smaller, | ||
stype = sys.bpchar, | ||
combinefunc = sys.bpchar_smaller, | ||
sortop = <, | ||
parallel = safe | ||
); | ||
|
||
-- varchar | ||
CREATE OR REPLACE AGGREGATE sys.max(sys.VARCHAR) | ||
( | ||
sfunc = sys.varchar_larger, | ||
stype = sys.varchar, | ||
combinefunc = sys.varchar_larger, | ||
sortop = >, | ||
parallel = safe | ||
); | ||
|
||
CREATE OR REPLACE AGGREGATE sys.min(sys.VARCHAR) | ||
( | ||
sfunc = sys.varchar_smaller, | ||
stype = sys.varchar, | ||
combinefunc = sys.varchar_smaller, | ||
sortop = <, | ||
parallel = safe | ||
); | ||
|
||
-- datetime | ||
CREATE OR REPLACE AGGREGATE sys.max(sys.DATETIME) | ||
( | ||
sfunc = sys.datetime_larger, | ||
stype = sys.datetime, | ||
combinefunc = sys.datetime_larger, | ||
sortop = >, | ||
parallel = safe | ||
); | ||
|
||
CREATE OR REPLACE AGGREGATE sys.min(sys.DATETIME) | ||
( | ||
sfunc = sys.datetime_smaller, | ||
stype = sys.datetime, | ||
combinefunc = sys.datetime_smaller, | ||
sortop = <, | ||
parallel = safe | ||
); | ||
|
||
-- datetime2 | ||
CREATE OR REPLACE AGGREGATE sys.max(sys.DATETIME2) | ||
( | ||
sfunc = sys.datetime2_larger, | ||
stype = sys.datetime2, | ||
combinefunc = sys.datetime2_larger, | ||
sortop = >, | ||
parallel = safe | ||
); | ||
|
||
CREATE OR REPLACE AGGREGATE sys.min(sys.DATETIME2) | ||
( | ||
sfunc = sys.datetime2_smaller, | ||
stype = sys.datetime2, | ||
combinefunc = sys.datetime2_smaller, | ||
sortop = <, | ||
parallel = safe | ||
); | ||
|
||
-- datetimeoffset | ||
CREATE OR REPLACE AGGREGATE sys.max(sys.DATETIMEOFFSET) | ||
( | ||
sfunc = sys.datetimeoffset_larger, | ||
stype = sys.datetimeoffset, | ||
combinefunc = sys.datetimeoffset_larger, | ||
sortop = >, | ||
parallel = safe | ||
); | ||
|
||
CREATE OR REPLACE AGGREGATE sys.min(sys.DATETIMEOFFSET) | ||
( | ||
sfunc = sys.datetimeoffset_smaller, | ||
stype = sys.datetimeoffset, | ||
combinefunc = sys.datetimeoffset_smaller, | ||
sortop = <, | ||
parallel = safe | ||
); | ||
|
||
-- smalldatetime | ||
CREATE OR REPLACE AGGREGATE sys.max(sys.SMALLDATETIME) | ||
( | ||
sfunc = sys.smalldatetime_larger, | ||
stype = sys.smalldatetime, | ||
combinefunc = sys.smalldatetime_larger, | ||
sortop = >, | ||
parallel = safe | ||
); | ||
|
||
CREATE OR REPLACE AGGREGATE sys.min(sys.SMALLDATETIME) | ||
( | ||
sfunc = sys.smalldatetime_smaller, | ||
stype = sys.smalldatetime, | ||
combinefunc = sys.smalldatetime_smaller, | ||
sortop = <, | ||
parallel = safe | ||
); | ||
|
||
-- Reset search_path to not affect any subsequent scripts | ||
SELECT set_config('search_path', trim(leading 'sys, ' from current_setting('search_path')), false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
DROP VIEW TestDatatypeAggSort_vu_prepare_char_view_max | ||
go | ||
DROP VIEW TestDatatypeAggSort_vu_prepare_char_view_min | ||
go | ||
DROP VIEW TestDatatypeAggSort_vu_prepare_varchar_view_max | ||
go | ||
DROP VIEW TestDatatypeAggSort_vu_prepare_varchar_view_min | ||
go | ||
DROP VIEW TestDatatypeAggSort_vu_prepare_datetime_view_max | ||
go | ||
DROP VIEW TestDatatypeAggSort_vu_prepare_datetime_view_min | ||
go | ||
DROP VIEW TestDatatypeAggSort_vu_prepare_datetime2_view_max | ||
go | ||
DROP VIEW TestDatatypeAggSort_vu_prepare_datetime2_view_min | ||
go | ||
DROP VIEW TestDatatypeAggSort_vu_prepare_datetimeoffset_view_max | ||
go | ||
DROP VIEW TestDatatypeAggSort_vu_prepare_datetimeoffset_view_min | ||
go | ||
DROP VIEW TestDatatypeAggSort_vu_prepare_smalldatetime_view_max | ||
go | ||
DROP VIEW TestDatatypeAggSort_vu_prepare_smalldatetime_view_min | ||
go | ||
|
||
DROP PROCEDURE TestDatatypeAggSort_vu_prepare_proc | ||
go | ||
|
||
DROP TABLE TestDatatypeAggSort_vu_prepare_tbl | ||
go | ||
|
||
DROP TABLE TestDatatypeAggSort_vu_prepare_tbl2 | ||
go |
Oops, something went wrong.