Skip to content

Commit

Permalink
Add vectorization for timestamp[tz] data types (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
japinli authored Jul 8, 2024
1 parent 7b30fbc commit 39e8604
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
18 changes: 18 additions & 0 deletions columnar/src/backend/columnar/sql/columnar--11.1-3--11.1-4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,21 @@ CREATE FUNCTION vtime_gt(time, time) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE
CREATE FUNCTION vtime_lt(time, time) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION vtime_le(time, time) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION vtime_ge(time, time) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;

-- timestamp

CREATE FUNCTION vtimestamp_eq(timestamp, timestamp) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION vtimestamp_ne(timestamp, timestamp) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION vtimestamp_gt(timestamp, timestamp) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION vtimestamp_lt(timestamp, timestamp) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION vtimestamp_le(timestamp, timestamp) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION vtimestamp_ge(timestamp, timestamp) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;

-- timestamptz

CREATE FUNCTION vtimestamptz_eq(timestamptz, timestamptz) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION vtimestamptz_ne(timestamptz, timestamptz) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION vtimestamptz_gt(timestamptz, timestamptz) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION vtimestamptz_lt(timestamptz, timestamptz) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION vtimestamptz_le(timestamptz, timestamptz) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION vtimestamptz_ge(timestamptz, timestamptz) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT;
8 changes: 7 additions & 1 deletion columnar/src/backend/columnar/vectorization/types/date.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
BUILD_CMP_OPERATOR_INT(date_, DateADT, DateADT)

// time (int64)
BUILD_CMP_OPERATOR_INT(time_, TimeADT, TimeADT)
BUILD_CMP_OPERATOR_INT(time_, TimeADT, TimeADT)

// timestamp (int64)
BUILD_CMP_OPERATOR_INT(timestamp_, Timestamp, Timestamp)

// timestamptz (int64)
BUILD_CMP_OPERATOR_INT(timestamptz_, TimestampTz, TimestampTz)
1 change: 1 addition & 0 deletions columnar/src/test/regress/columnar_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ test: columnar_cache
test: columnar_aggregates
test: columnar_upsert
test: columnar_customindex
test: columnar_vectorization
24 changes: 24 additions & 0 deletions columnar/src/test/regress/expected/columnar_vectorization.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE TABLE t (id int, ts timestamp) USING columnar;
INSERT INTO t SELECT id, now() + id * '1 day'::interval FROM generate_series(1, 100000) id;
EXPLAIN (costs off) SELECT * FROM t WHERE ts between '2026-01-01'::timestamp and '2026-02-01'::timestamp;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Custom Scan (ColumnarScan) on t
Columnar Projected Columns: id, ts
Columnar Chunk Group Filters: ((ts >= 'Thu Jan 01 00:00:00 2026'::timestamp without time zone) AND (ts <= 'Sun Feb 01 00:00:00 2026'::timestamp without time zone))
Columnar Vectorized Filter: ((ts >= 'Thu Jan 01 00:00:00 2026'::timestamp without time zone) AND (ts <= 'Sun Feb 01 00:00:00 2026'::timestamp without time zone))
(4 rows)

DROP TABLE t;
CREATE TABLE t (id int, ts timestamptz) USING columnar;
INSERT INTO t SELECT id, now() + id * '1 day'::interval FROM generate_series(1, 100000) id;
EXPLAIN (costs off) SELECT * FROM t WHERE ts between '2026-01-01'::timestamptz and '2026-02-01'::timestamptz;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Custom Scan (ColumnarScan) on t
Columnar Projected Columns: id, ts
Columnar Chunk Group Filters: ((ts >= 'Thu Jan 01 00:00:00 2026 PST'::timestamp with time zone) AND (ts <= 'Sun Feb 01 00:00:00 2026 PST'::timestamp with time zone))
Columnar Vectorized Filter: ((ts >= 'Thu Jan 01 00:00:00 2026 PST'::timestamp with time zone) AND (ts <= 'Sun Feb 01 00:00:00 2026 PST'::timestamp with time zone))
(4 rows)

DROP TABLE t;
9 changes: 9 additions & 0 deletions columnar/src/test/regress/sql/columnar_vectorization.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE t (id int, ts timestamp) USING columnar;
INSERT INTO t SELECT id, now() + id * '1 day'::interval FROM generate_series(1, 100000) id;
EXPLAIN (costs off) SELECT * FROM t WHERE ts between '2026-01-01'::timestamp and '2026-02-01'::timestamp;
DROP TABLE t;

CREATE TABLE t (id int, ts timestamptz) USING columnar;
INSERT INTO t SELECT id, now() + id * '1 day'::interval FROM generate_series(1, 100000) id;
EXPLAIN (costs off) SELECT * FROM t WHERE ts between '2026-01-01'::timestamptz and '2026-02-01'::timestamptz;
DROP TABLE t;

0 comments on commit 39e8604

Please sign in to comment.