Skip to content

Commit

Permalink
[columnar] WHERE on INTEGER column not working when SELECT includes c…
Browse files Browse the repository at this point in the history
…ertain custom types (#70)

* Fixes github #46. Handling now types which have `len` larger that 8
  byte by directly copying value.
  • Loading branch information
mkaruza authored and wuputah committed Mar 20, 2023
1 parent c08a1b5 commit 4f5b508
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 9 deletions.
23 changes: 18 additions & 5 deletions columnar/src/backend/columnar/columnar_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2045,12 +2045,25 @@ ReadChunkGroupNextVector(ChunkGroupReadState *chunkGroupReadState, Datum *column
int8 *writeColumnRowPosition =
(int8 *) vectorColumn->value + columnValueOffset[columnIndex];

store_att_byval(writeColumnRowPosition,
chunkGroupData->valueArray[columnIndex][rowIndex],
vectorColumn->columnTypeLen);

vectorColumn->isnull[vectorColumn->dimension] = false;

/*
* For data types which have len less or equal 8 we can
* use `store_att_byval` function.
*/
if (vectorColumn->columnTypeLen <= 8)
{
store_att_byval(writeColumnRowPosition,
chunkGroupData->valueArray[columnIndex][rowIndex],
vectorColumn->columnTypeLen);
}
else
{
memcpy(writeColumnRowPosition,
(int8 *)(chunkGroupData->valueArray[columnIndex][rowIndex]),
vectorColumn->columnTypeLen);
}

vectorColumn->isnull[vectorColumn->dimension] = false;
}

vectorColumn->dimension++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,16 @@ CreateVectorTupleTableSlot(TupleDesc tupleDesc)
int16 vectorColumnTypeLen =
columnTypeLen == -1 ? sizeof(Datum) : get_typlen(columnTypeOid);

/*
* We consider that type is passed by val also for cases where we have
* typlen == -1. This is because we use pointer to VARLEN type and don't
* construct our own object.
*/
bool vectorColumnIsVal = vectorColumnTypeLen <= sizeof(Datum);

vectorColumn = BuildVectorColumn(COLUMNAR_VECTOR_COLUMN_SIZE,
vectorColumnTypeLen,
columnTypeLen == -1,
vectorColumnIsVal,
vectorTTS->rowNumber);

vectorTTS->tts.tts_values[i] = PointerGetDatum(vectorColumn);
Expand All @@ -89,7 +96,7 @@ extractTupleFromVectorSlot(TupleTableSlot *out, VectorTupleTableSlot *vectorSlot

int8 *rawColumRawData = (int8*) column->value + column->columnTypeLen * index;

out->tts_values[bmsMember] = fetch_att(rawColumRawData, true, column->columnTypeLen);
out->tts_values[bmsMember] = fetch_att(rawColumRawData, column->columnIsVal, column->columnTypeLen);
out->tts_isnull[bmsMember] = column->isnull[index];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ SELECT columnar.alter_columnar_table_set('test', compression => 'lz4');
INSERT INTO test VALUES(1);
VACUUM VERBOSE test;
INFO: statistics for "test":
storage id: 10000000135
storage id: 10000000136
total file size: 24576, total data size: 6
compression rate: 0.83x
total row count: 1, stripe count: 1, average rows per stripe: 1
Expand All @@ -72,7 +72,7 @@ chunk count: 1, containing data for dropped columns: 0, lz4 compressed: 1
ALTER TABLE test ALTER COLUMN i TYPE int8;
VACUUM VERBOSE test;
INFO: statistics for "test":
storage id: 10000000136
storage id: 10000000137
total file size: 24576, total data size: 10
compression rate: 0.90x
total row count: 1, stripe count: 1, average rows per stripe: 1
Expand Down
32 changes: 32 additions & 0 deletions columnar/src/test/regress/expected/columnar_query.out
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,35 @@ SELECT * FROM t WHERE a = 1 ORDER BY b LIMIT 1;
(1 row)

DROP TABLE t;
--
-- [columnar] WHERE on INTEGER column not working when SELECT includes certain custom types
--
CREATE TABLE t(a INT, b point, c TEXT) USING columnar;
INSERT INTO t SELECT g, point(1, g), 'abc_' || g FROM generate_series(0,100) AS g;
EXPLAIN (analyze off, costs off, timing off, summary off)
SELECT * FROM t WHERE a >= 90;
QUERY PLAN
-------------------------------------------
Custom Scan (ColumnarScan) on t
Columnar Projected Columns: a, b, c
Columnar Chunk Group Filters: (a >= 90)
Columnar Vectorized Filter: (a >= 90)
(4 rows)

SELECT * FROM t WHERE a >= 90;
a | b | c
-----+---------+---------
90 | (1,90) | abc_90
91 | (1,91) | abc_91
92 | (1,92) | abc_92
93 | (1,93) | abc_93
94 | (1,94) | abc_94
95 | (1,95) | abc_95
96 | (1,96) | abc_96
97 | (1,97) | abc_97
98 | (1,98) | abc_98
99 | (1,99) | abc_99
100 | (1,100) | abc_100
(11 rows)

DROP TABLE t;
16 changes: 16 additions & 0 deletions columnar/src/test/regress/sql/columnar_query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,19 @@ SELECT * FROM t WHERE a = 1 ORDER BY b LIMIT 1;
SELECT * FROM t WHERE a = 1 ORDER BY b LIMIT 1;

DROP TABLE t;


--
-- [columnar] WHERE on INTEGER column not working when SELECT includes certain custom types
--

CREATE TABLE t(a INT, b point, c TEXT) USING columnar;

INSERT INTO t SELECT g, point(1, g), 'abc_' || g FROM generate_series(0,100) AS g;

EXPLAIN (analyze off, costs off, timing off, summary off)
SELECT * FROM t WHERE a >= 90;

SELECT * FROM t WHERE a >= 90;

DROP TABLE t;

0 comments on commit 4f5b508

Please sign in to comment.