-
Notifications
You must be signed in to change notification settings - Fork 916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve compression datatype handling #6081
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fixes: #6081 Improve compressed DML datatype handling | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
#include <nodes/pg_list.h> | ||
#include <nodes/print.h> | ||
#include <parser/parsetree.h> | ||
#include <parser/parse_coerce.h> | ||
#include <storage/lmgr.h> | ||
#include <storage/predicate.h> | ||
#include <utils/builtins.h> | ||
|
@@ -1962,8 +1963,18 @@ create_segment_filter_scankey(RowDecompressor *decompressor, char *segment_filte | |
elog(ERROR, "no btree opfamily for type \"%s\"", format_type_be(atttypid)); | ||
|
||
Oid opr = get_opfamily_member(tce->btree_opf, atttypid, atttypid, strategy); | ||
Assert(OidIsValid(opr)); | ||
/* We should never end up here but: no operator, no optimization */ | ||
|
||
/* | ||
* Fall back to btree operator input type when it is binary compatible with | ||
* the column type and no operator for column type could be found. | ||
*/ | ||
if (!OidIsValid(opr) && IsBinaryCoercible(atttypid, tce->btree_opintype)) | ||
{ | ||
opr = | ||
get_opfamily_member(tce->btree_opf, tce->btree_opintype, tce->btree_opintype, strategy); | ||
} | ||
|
||
/* No operator could be found so we can't create the scankey. */ | ||
if (!OidIsValid(opr)) | ||
return num_scankeys; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Might be out of the scope of this PR. But I think we should also remove the following Assert in Line 1971/1982 ( Again, we have an Assert followed by an if/else on the same condition. The assert prevents proper testing of this branch in a debug build. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense to me. |
||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -86,3 +86,43 @@ INSERT INTO mytab SELECT '2022-10-07 05:30:10+05:30'::timestamp with time zone, | |||||
EXPLAIN (costs off) SELECT * FROM :chunk_table; | ||||||
DROP TABLE mytab CASCADE; | ||||||
|
||||||
-- test varchar segmentby | ||||||
CREATE TABLE comp_seg_varchar ( | ||||||
time timestamptz NOT NULL, | ||||||
source_id varchar(64) NOT NULL, | ||||||
label varchar NOT NULL, | ||||||
data jsonb | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit
Suggested change
|
||||||
); | ||||||
|
||||||
SELECT table_name FROM create_hypertable('comp_seg_varchar', 'time'); | ||||||
|
||||||
CREATE UNIQUE INDEX ON comp_seg_varchar(source_id, label, "time" DESC); | ||||||
|
||||||
ALTER TABLE comp_seg_varchar SET(timescaledb.compress, timescaledb.compress_segmentby = 'source_id, label', timescaledb.compress_orderby = 'time'); | ||||||
|
||||||
INSERT INTO comp_seg_varchar | ||||||
SELECT time, source_id, label, '{}' AS data | ||||||
FROM | ||||||
generate_series('1990-01-01'::timestamptz, '1990-01-10'::timestamptz, INTERVAL '1 day') AS g1(time), | ||||||
generate_series(1, 3, 1 ) AS g2(source_id), | ||||||
generate_series(1, 3, 1 ) AS g3(label); | ||||||
|
||||||
SELECT compress_chunk(c) FROM show_chunks('comp_seg_varchar') c; | ||||||
|
||||||
|
||||||
-- all tuples should come from compressed chunks | ||||||
EXPLAIN (analyze,costs off, timing off, summary off) SELECT * FROM comp_seg_varchar; | ||||||
|
||||||
INSERT INTO comp_seg_varchar(time, source_id, label, data) VALUES ('1990-01-02 00:00:00+00', 'test', 'test', '{}'::jsonb) | ||||||
ON CONFLICT (source_id, label, time) DO UPDATE SET data = '{"update": true}'; | ||||||
|
||||||
-- no tuples should be moved into uncompressed | ||||||
EXPLAIN (analyze,costs off, timing off, summary off) SELECT * FROM comp_seg_varchar; | ||||||
|
||||||
INSERT INTO comp_seg_varchar(time, source_id, label, data) VALUES ('1990-01-02 00:00:00+00', '1', '2', '{}'::jsonb) | ||||||
ON CONFLICT (source_id, label, time) DO UPDATE SET data = '{"update": true}'; | ||||||
|
||||||
-- 1 batch should be moved into uncompressed | ||||||
EXPLAIN (analyze,costs off, timing off, summary off) SELECT * FROM comp_seg_varchar; | ||||||
|
||||||
DROP TABLE comp_seg_varchar; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov complains about missing coverage. However, the test case seems to cover this part of the code and removing these lines triggers a test failure. So, it seems to be tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov has been all over the place lately, not sure whats going on with it. Reporting random lines being untested which are in the same branch where all other lines have been tested.