From bc5e39d67a64ccc40f399e23eacd7fe2647dd036 Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenkov <36882414+akuzm@users.noreply.github.com> Date: Tue, 31 Oct 2023 20:07:31 +0100 Subject: [PATCH] Vectorize the comparison operators for Date type This uses our normal arithmetic vectorized operators. --- .../pred_vector_const_arithmetic_all.c | 8 +++ .../decompress_chunk/vector_predicates.c | 1 + tsl/test/expected/decompress_vector_qual.out | 51 +++++++++++++++++++ tsl/test/sql/decompress_vector_qual.sql | 16 ++++++ 4 files changed, 76 insertions(+) diff --git a/tsl/src/nodes/decompress_chunk/pred_vector_const_arithmetic_all.c b/tsl/src/nodes/decompress_chunk/pred_vector_const_arithmetic_all.c index bf089f4bc..ea5d409a0 100644 --- a/tsl/src/nodes/decompress_chunk/pred_vector_const_arithmetic_all.c +++ b/tsl/src/nodes/decompress_chunk/pred_vector_const_arithmetic_all.c @@ -84,3 +84,11 @@ #define PG_PREDICATE(X) F_FLOAT4##X #include "pred_vector_const_arithmetic_type_pair.c" + +/* date functions. */ +#define VECTOR_CTYPE DateADT +#define CONST_CTYPE DateADT +#define CONST_CONVERSION(X) DatumGetDateADT(X) +#define PG_PREDICATE(X) F_DATE_##X + +#include "pred_vector_const_arithmetic_type_pair.c" diff --git a/tsl/src/nodes/decompress_chunk/vector_predicates.c b/tsl/src/nodes/decompress_chunk/vector_predicates.c index c878fde6d..3f91a0a91 100644 --- a/tsl/src/nodes/decompress_chunk/vector_predicates.c +++ b/tsl/src/nodes/decompress_chunk/vector_predicates.c @@ -10,6 +10,7 @@ #include +#include #include #include "compat/compat.h" diff --git a/tsl/test/expected/decompress_vector_qual.out b/tsl/test/expected/decompress_vector_qual.out index 331b189d8..9e13d119c 100644 --- a/tsl/test/expected/decompress_vector_qual.out +++ b/tsl/test/expected/decompress_vector_qual.out @@ -217,3 +217,54 @@ set timescaledb.debug_require_vector_qual to 'only'; select count(*) from vectorqual where metric4 is null; ERROR: debug: encountered non-vector quals when they are disabled \set ON_ERROR_STOP 1 +-- Date columns +create table date_table(ts date); +select create_hypertable('date_table', 'ts'); +NOTICE: adding not-null constraint to column "ts" + create_hypertable +------------------------- + (3,public,date_table,t) +(1 row) + +alter table date_table set (timescaledb.compress); +insert into date_table values ('2021-01-01'), ('2021-01-02'), + ('2021-01-03'); +select count(compress_chunk(x, true)) from show_chunks('date_table') x; + count +------- + 1 +(1 row) + +set timescaledb.debug_require_vector_qual to 'only'; +select * from date_table where ts > '2021-01-02'; + ts +------------ + 01-03-2021 +(1 row) + +select * from date_table where ts >= '2021-01-02'; + ts +------------ + 01-03-2021 + 01-02-2021 +(2 rows) + +select * from date_table where ts = '2021-01-02'; + ts +------------ + 01-02-2021 +(1 row) + +select * from date_table where ts <= '2021-01-02'; + ts +------------ + 01-02-2021 + 01-01-2021 +(2 rows) + +select * from date_table where ts < '2021-01-02'; + ts +------------ + 01-01-2021 +(1 row) + diff --git a/tsl/test/sql/decompress_vector_qual.sql b/tsl/test/sql/decompress_vector_qual.sql index 405ef27d7..6168faf8e 100644 --- a/tsl/test/sql/decompress_vector_qual.sql +++ b/tsl/test/sql/decompress_vector_qual.sql @@ -87,3 +87,19 @@ select count(*) from vectorqual where metric4 > 4; set timescaledb.debug_require_vector_qual to 'only'; select count(*) from vectorqual where metric4 is null; \set ON_ERROR_STOP 1 + + +-- Date columns +create table date_table(ts date); +select create_hypertable('date_table', 'ts'); +alter table date_table set (timescaledb.compress); +insert into date_table values ('2021-01-01'), ('2021-01-02'), + ('2021-01-03'); +select count(compress_chunk(x, true)) from show_chunks('date_table') x; + +set timescaledb.debug_require_vector_qual to 'only'; +select * from date_table where ts > '2021-01-02'; +select * from date_table where ts >= '2021-01-02'; +select * from date_table where ts = '2021-01-02'; +select * from date_table where ts <= '2021-01-02'; +select * from date_table where ts < '2021-01-02';