mirror of https://github.com/citusdata/citus.git
Columnar: add explain info for chunk filtering (#4554)
Co-authored-by: Jeff Davis <jefdavi@microsoft.com>pull/4557/head
parent
0581df23f4
commit
0b5551faaf
|
@ -68,6 +68,8 @@ static void CStoreScan_BeginCustomScan(CustomScanState *node, EState *estate, in
|
||||||
static TupleTableSlot * CStoreScan_ExecCustomScan(CustomScanState *node);
|
static TupleTableSlot * CStoreScan_ExecCustomScan(CustomScanState *node);
|
||||||
static void CStoreScan_EndCustomScan(CustomScanState *node);
|
static void CStoreScan_EndCustomScan(CustomScanState *node);
|
||||||
static void CStoreScan_ReScanCustomScan(CustomScanState *node);
|
static void CStoreScan_ReScanCustomScan(CustomScanState *node);
|
||||||
|
static void CStoreScan_ExplainCustomScan(CustomScanState *node, List *ancestors,
|
||||||
|
ExplainState *es);
|
||||||
|
|
||||||
/* saved hook value in case of unload */
|
/* saved hook value in case of unload */
|
||||||
static set_rel_pathlist_hook_type PreviousSetRelPathlistHook = NULL;
|
static set_rel_pathlist_hook_type PreviousSetRelPathlistHook = NULL;
|
||||||
|
@ -93,7 +95,7 @@ const struct CustomExecMethods CStoreExecuteMethods = {
|
||||||
.EndCustomScan = CStoreScan_EndCustomScan,
|
.EndCustomScan = CStoreScan_EndCustomScan,
|
||||||
.ReScanCustomScan = CStoreScan_ReScanCustomScan,
|
.ReScanCustomScan = CStoreScan_ReScanCustomScan,
|
||||||
|
|
||||||
.ExplainCustomScan = NULL,
|
.ExplainCustomScan = CStoreScan_ExplainCustomScan,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -439,4 +441,19 @@ CStoreScan_ReScanCustomScan(CustomScanState *node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
CStoreScan_ExplainCustomScan(CustomScanState *node, List *ancestors,
|
||||||
|
ExplainState *es)
|
||||||
|
{
|
||||||
|
TableScanDesc scanDesc = node->ss.ss_currentScanDesc;
|
||||||
|
|
||||||
|
if (scanDesc != NULL)
|
||||||
|
{
|
||||||
|
int64 chunksFiltered = ColumnarGetChunksFiltered(scanDesc);
|
||||||
|
ExplainPropertyInteger("Columnar Chunks Removed by Filter", NULL,
|
||||||
|
chunksFiltered, es);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* HAS_TABLEAM */
|
#endif /* HAS_TABLEAM */
|
||||||
|
|
|
@ -44,7 +44,8 @@ static StripeBuffers * LoadFilteredStripeBuffers(Relation relation,
|
||||||
StripeMetadata *stripeMetadata,
|
StripeMetadata *stripeMetadata,
|
||||||
TupleDesc tupleDescriptor,
|
TupleDesc tupleDescriptor,
|
||||||
List *projectedColumnList,
|
List *projectedColumnList,
|
||||||
List *whereClauseList);
|
List *whereClauseList,
|
||||||
|
int64 *chunksFiltered);
|
||||||
static void ReadStripeNextRow(StripeBuffers *stripeBuffers, List *projectedColumnList,
|
static void ReadStripeNextRow(StripeBuffers *stripeBuffers, List *projectedColumnList,
|
||||||
uint64 chunkIndex, uint64 chunkRowIndex,
|
uint64 chunkIndex, uint64 chunkRowIndex,
|
||||||
ChunkData *chunkData, Datum *columnValues,
|
ChunkData *chunkData, Datum *columnValues,
|
||||||
|
@ -54,7 +55,8 @@ static ColumnBuffers * LoadColumnBuffers(Relation relation,
|
||||||
uint32 chunkCount, uint64 stripeOffset,
|
uint32 chunkCount, uint64 stripeOffset,
|
||||||
Form_pg_attribute attributeForm);
|
Form_pg_attribute attributeForm);
|
||||||
static bool * SelectedChunkMask(StripeSkipList *stripeSkipList,
|
static bool * SelectedChunkMask(StripeSkipList *stripeSkipList,
|
||||||
List *projectedColumnList, List *whereClauseList);
|
List *projectedColumnList, List *whereClauseList,
|
||||||
|
int64 *chunksFiltered);
|
||||||
static List * BuildRestrictInfoList(List *whereClauseList);
|
static List * BuildRestrictInfoList(List *whereClauseList);
|
||||||
static Node * BuildBaseConstraint(Var *variable);
|
static Node * BuildBaseConstraint(Var *variable);
|
||||||
static OpExpr * MakeOpExpression(Var *variable, int16 strategyNumber);
|
static OpExpr * MakeOpExpression(Var *variable, int16 strategyNumber);
|
||||||
|
@ -104,6 +106,7 @@ CStoreBeginRead(Relation relation, TupleDesc tupleDescriptor,
|
||||||
readState->stripeBuffers = NULL;
|
readState->stripeBuffers = NULL;
|
||||||
readState->readStripeCount = 0;
|
readState->readStripeCount = 0;
|
||||||
readState->stripeReadRowCount = 0;
|
readState->stripeReadRowCount = 0;
|
||||||
|
readState->chunksFiltered = 0;
|
||||||
readState->tupleDescriptor = tupleDescriptor;
|
readState->tupleDescriptor = tupleDescriptor;
|
||||||
readState->stripeReadContext = stripeReadContext;
|
readState->stripeReadContext = stripeReadContext;
|
||||||
readState->chunkData = NULL;
|
readState->chunkData = NULL;
|
||||||
|
@ -153,7 +156,9 @@ CStoreReadNextRow(TableReadState *readState, Datum *columnValues, bool *columnNu
|
||||||
readState->
|
readState->
|
||||||
projectedColumnList,
|
projectedColumnList,
|
||||||
readState->
|
readState->
|
||||||
whereClauseList);
|
whereClauseList,
|
||||||
|
&readState->
|
||||||
|
chunksFiltered);
|
||||||
readState->readStripeCount++;
|
readState->readStripeCount++;
|
||||||
readState->currentStripeMetadata = stripeMetadata;
|
readState->currentStripeMetadata = stripeMetadata;
|
||||||
|
|
||||||
|
@ -332,7 +337,7 @@ CStoreTableRowCount(Relation relation)
|
||||||
static StripeBuffers *
|
static StripeBuffers *
|
||||||
LoadFilteredStripeBuffers(Relation relation, StripeMetadata *stripeMetadata,
|
LoadFilteredStripeBuffers(Relation relation, StripeMetadata *stripeMetadata,
|
||||||
TupleDesc tupleDescriptor, List *projectedColumnList,
|
TupleDesc tupleDescriptor, List *projectedColumnList,
|
||||||
List *whereClauseList)
|
List *whereClauseList, int64 *chunksFiltered)
|
||||||
{
|
{
|
||||||
uint32 columnIndex = 0;
|
uint32 columnIndex = 0;
|
||||||
uint32 columnCount = tupleDescriptor->natts;
|
uint32 columnCount = tupleDescriptor->natts;
|
||||||
|
@ -345,7 +350,7 @@ LoadFilteredStripeBuffers(Relation relation, StripeMetadata *stripeMetadata,
|
||||||
stripeMetadata->chunkCount);
|
stripeMetadata->chunkCount);
|
||||||
|
|
||||||
bool *selectedChunkMask = SelectedChunkMask(stripeSkipList, projectedColumnList,
|
bool *selectedChunkMask = SelectedChunkMask(stripeSkipList, projectedColumnList,
|
||||||
whereClauseList);
|
whereClauseList, chunksFiltered);
|
||||||
|
|
||||||
StripeSkipList *selectedChunkSkipList =
|
StripeSkipList *selectedChunkSkipList =
|
||||||
SelectedChunkSkipList(stripeSkipList, projectedColumnMask,
|
SelectedChunkSkipList(stripeSkipList, projectedColumnMask,
|
||||||
|
@ -474,7 +479,7 @@ LoadColumnBuffers(Relation relation, ColumnChunkSkipNode *chunkSkipNodeArray,
|
||||||
*/
|
*/
|
||||||
static bool *
|
static bool *
|
||||||
SelectedChunkMask(StripeSkipList *stripeSkipList, List *projectedColumnList,
|
SelectedChunkMask(StripeSkipList *stripeSkipList, List *projectedColumnList,
|
||||||
List *whereClauseList)
|
List *whereClauseList, int64 *chunksFiltered)
|
||||||
{
|
{
|
||||||
ListCell *columnCell = NULL;
|
ListCell *columnCell = NULL;
|
||||||
uint32 chunkIndex = 0;
|
uint32 chunkIndex = 0;
|
||||||
|
@ -527,6 +532,7 @@ SelectedChunkMask(StripeSkipList *stripeSkipList, List *projectedColumnList,
|
||||||
if (predicateRefuted)
|
if (predicateRefuted)
|
||||||
{
|
{
|
||||||
selectedChunkMask[chunkIndex] = false;
|
selectedChunkMask[chunkIndex] = false;
|
||||||
|
*chunksFiltered += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1156,6 +1156,26 @@ cstore_tableam_finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the number of chunks filtered out during the given scan.
|
||||||
|
*/
|
||||||
|
int64
|
||||||
|
ColumnarGetChunksFiltered(TableScanDesc scanDesc)
|
||||||
|
{
|
||||||
|
CStoreScanDesc cstoreScanDesc = (CStoreScanDesc) scanDesc;
|
||||||
|
TableReadState *readState = cstoreScanDesc->cs_readState;
|
||||||
|
|
||||||
|
if (readState != NULL)
|
||||||
|
{
|
||||||
|
return readState->chunksFiltered;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Implementation of TupleTableSlotOps.copy_heap_tuple for TTSOpsColumnar.
|
* Implementation of TupleTableSlotOps.copy_heap_tuple for TTSOpsColumnar.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -236,6 +236,7 @@ typedef struct TableReadState
|
||||||
StripeBuffers *stripeBuffers;
|
StripeBuffers *stripeBuffers;
|
||||||
uint32 readStripeCount;
|
uint32 readStripeCount;
|
||||||
uint64 stripeReadRowCount;
|
uint64 stripeReadRowCount;
|
||||||
|
int64 chunksFiltered;
|
||||||
ChunkData *chunkData;
|
ChunkData *chunkData;
|
||||||
int32 deserializedChunkIndex;
|
int32 deserializedChunkIndex;
|
||||||
} TableReadState;
|
} TableReadState;
|
||||||
|
|
|
@ -18,7 +18,7 @@ extern TableScanDesc cstore_beginscan_extended(Relation relation, Snapshot snaps
|
||||||
ParallelTableScanDesc parallel_scan,
|
ParallelTableScanDesc parallel_scan,
|
||||||
uint32 flags, Bitmapset *attr_needed,
|
uint32 flags, Bitmapset *attr_needed,
|
||||||
List *scanQual);
|
List *scanQual);
|
||||||
|
extern int64 ColumnarGetChunksFiltered(TableScanDesc scanDesc);
|
||||||
extern bool IsCStoreTableAmTable(Oid relationId);
|
extern bool IsCStoreTableAmTable(Oid relationId);
|
||||||
extern TableDDLCommand * ColumnarGetTableOptionsDDL(Oid relationId);
|
extern TableDDLCommand * ColumnarGetTableOptionsDDL(Oid relationId);
|
||||||
extern char * GetShardedTableDDLCommandColumnar(uint64 shardId, void *context);
|
extern char * GetShardedTableDDLCommandColumnar(uint64 shardId, void *context);
|
||||||
|
|
|
@ -71,3 +71,9 @@ B
|
||||||
\.
|
\.
|
||||||
|
|
||||||
SELECT * FROM collation_chunk_filtering_test WHERE A > 'B';
|
SELECT * FROM collation_chunk_filtering_test WHERE A > 'B';
|
||||||
|
|
||||||
|
CREATE TABLE simple_chunk_filtering(i int) USING COLUMNAR;
|
||||||
|
INSERT INTO simple_chunk_filtering SELECT generate_series(0,234567);
|
||||||
|
EXPLAIN (analyze on, costs off, timing off, summary off)
|
||||||
|
SELECT * FROM simple_chunk_filtering WHERE i > 123456;
|
||||||
|
DROP TABLE simple_chunk_filtering;
|
||||||
|
|
|
@ -118,3 +118,16 @@ SELECT * FROM collation_chunk_filtering_test WHERE A > 'B';
|
||||||
Å
|
Å
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
CREATE TABLE simple_chunk_filtering(i int) USING COLUMNAR;
|
||||||
|
INSERT INTO simple_chunk_filtering SELECT generate_series(0,234567);
|
||||||
|
EXPLAIN (analyze on, costs off, timing off, summary off)
|
||||||
|
SELECT * FROM simple_chunk_filtering WHERE i > 123456;
|
||||||
|
QUERY PLAN
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
Custom Scan (ColumnarScan) on simple_chunk_filtering (actual rows=111111 loops=1)
|
||||||
|
Filter: (i > 123456)
|
||||||
|
Rows Removed by Filter: 3457
|
||||||
|
Columnar Chunks Removed by Filter: 12
|
||||||
|
(4 rows)
|
||||||
|
|
||||||
|
DROP TABLE simple_chunk_filtering;
|
||||||
|
|
Loading…
Reference in New Issue