Skip to content
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

Implement vectorized filters #5915

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ bool ts_shutdown_bgw = false;
char *ts_current_timestamp_mock = NULL;
#endif

#ifdef TS_DEBUG
jnidzwetzki marked this conversation as resolved.
Show resolved Hide resolved
static const struct config_enum_entry require_vector_qual_options[] = {
{ "allow", RVQ_Allow, false },
{ "forbid", RVQ_Forbid, false },
{ "only", RVQ_Only, false },
{ NULL, 0, false }
};
#endif

DebugRequireVectorQual ts_guc_debug_require_vector_qual = RVQ_Allow;

static bool ts_guc_enable_hypertable_create = true;
static bool ts_guc_enable_hypertable_compression = true;
static bool ts_guc_enable_cagg_create = true;
Expand Down Expand Up @@ -725,6 +736,24 @@ _guc_init(void)
/* assign_hook= */ NULL,
/* show_hook= */ NULL);

DefineCustomEnumVariable(/* name= */ "timescaledb.debug_require_vector_qual",
/* short_desc= */
"ensure that non-vectorized or vectorized filters are used in "
"DecompressChunk node",
/* long_desc= */
"this is for debugging purposes, to let us check if the vectorized "
"quals are used or not. EXPLAIN differs after PG15 for custom nodes, "
"and "
"using the test templates is a pain",
/* valueAddr= */ (int *) &ts_guc_debug_require_vector_qual,
/* bootValue= */ RVQ_Allow,
/* options = */ require_vector_qual_options,
/* context= */ PGC_USERSET,
/* flags= */ 0,
/* check_hook= */ NULL,
/* assign_hook= */ NULL,
/* show_hook= */ NULL);

DefineCustomBoolVariable(/* name= */ "timescaledb.debug_require_batch_sorted_merge",
/* short_desc= */ "require batch sorted merge in DecompressChunk node",
/* long_desc= */ "this is for debugging purposes",
Expand Down
9 changes: 9 additions & 0 deletions src/guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ extern char *ts_current_timestamp_mock;
#define ts_shutdown_bgw false
#endif

typedef enum DebugRequireVectorQual
{
RVQ_Allow = 0,
RVQ_Forbid,
RVQ_Only
} DebugRequireVectorQual;

extern TSDLLEXPORT DebugRequireVectorQual ts_guc_debug_require_vector_qual;

extern TSDLLEXPORT bool ts_guc_debug_require_batch_sorted_merge;

void _guc_init(void);
Expand Down
1 change: 1 addition & 0 deletions tsl/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ add_subdirectory(bgw_policy)
add_subdirectory(compression)
add_subdirectory(continuous_aggs)
add_subdirectory(fdw)
add_subdirectory(import)
add_subdirectory(nodes)
add_subdirectory(remote)
2 changes: 2 additions & 0 deletions tsl/src/import/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ts_explain.c)
target_sources(${TSL_LIBRARY_NAME} PRIVATE ${SOURCES})
107 changes: 107 additions & 0 deletions tsl/src/import/ts_explain.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* This file and its contents are licensed under the Timescale License.
* Please see the included NOTICE for copyright information and
* LICENSE-TIMESCALE for a copy of the license.
*/

/*
* This file contains source code that was copied and/or modified from
* the PostgreSQL database, which is licensed under the open-source
* PostgreSQL License. Please see the NOTICE at the top level
* directory for a copy of the PostgreSQL License.
*/

#include "ts_explain.h"

#include <commands/explain.h>
#include <nodes/makefuncs.h>
#include <utils/ruleutils.h>

#include "compat/compat.h"

/*
* Show a generic expression
*/
static void
ts_show_expression(Node *node, const char *qlabel, PlanState *planstate, List *ancestors,
bool useprefix, ExplainState *es)
{
List *context;
char *exprstr;

/* Set up deparsing context */
#if PG13_LT
context = set_deparse_context_planstate(es->deparse_cxt, (Node *) planstate, ancestors);
#else
context = set_deparse_context_plan(es->deparse_cxt, planstate->plan, ancestors);
#endif

/* Deparse the expression */
exprstr = deparse_expression(node, context, useprefix, false);

/* And add to es->str */
ExplainPropertyText(qlabel, exprstr, es);
}

/*
* Show a qualifier expression (which is a List with implicit AND semantics)
*/
static void
ts_show_qual(List *qual, const char *qlabel, PlanState *planstate, List *ancestors, bool useprefix,
ExplainState *es)
{
Node *node;

/* No work if empty qual */
if (qual == NIL)
return;

/* Convert AND list to explicit AND */
node = (Node *) make_ands_explicit(qual);

/* And show it */
ts_show_expression(node, qlabel, planstate, ancestors, useprefix, es);
}

/*
* Show a qualifier expression for a scan plan node
*/
void
ts_show_scan_qual(List *qual, const char *qlabel, PlanState *planstate, List *ancestors,
ExplainState *es)
{
bool useprefix;

useprefix = (IsA(planstate->plan, SubqueryScan) || es->verbose);
ts_show_qual(qual, qlabel, planstate, ancestors, useprefix, es);
}

/*
* If it's EXPLAIN ANALYZE, show instrumentation information for a plan node
*
* "which" identifies which instrumentation counter to print
*/
void
ts_show_instrumentation_count(const char *qlabel, int which, PlanState *planstate, ExplainState *es)
{
double nfiltered;
double nloops;

if (!es->analyze || !planstate->instrument)
return;

if (which == 2)
nfiltered = planstate->instrument->nfiltered2;

Check warning on line 94 in tsl/src/import/ts_explain.c

View check run for this annotation

Codecov / codecov/patch

tsl/src/import/ts_explain.c#L94

Added line #L94 was not covered by tests
else
nfiltered = planstate->instrument->nfiltered1;
nloops = planstate->instrument->nloops;

/* In text mode, suppress zero counts; they're not interesting enough */
if (nfiltered > 0 || es->format != EXPLAIN_FORMAT_TEXT)
{
if (nloops > 0)
ExplainPropertyFloat(qlabel, NULL, nfiltered / nloops, 0, es);
else
ExplainPropertyFloat(qlabel, NULL, 0.0, 0, es);

Check warning on line 105 in tsl/src/import/ts_explain.c

View check run for this annotation

Codecov / codecov/patch

tsl/src/import/ts_explain.c#L105

Added line #L105 was not covered by tests
}
}
26 changes: 26 additions & 0 deletions tsl/src/import/ts_explain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This file and its contents are licensed under the Timescale License.
* Please see the included NOTICE for copyright information and
* LICENSE-TIMESCALE for a copy of the license.
*/

/*
* This file contains source code that was copied and/or modified from
* the PostgreSQL database, which is licensed under the open-source
* PostgreSQL License. Please see the NOTICE at the top level
* directory for a copy of the PostgreSQL License.
*/

#pragma once

#include <postgres.h>

#include <commands/explain.h>
#include <nodes/execnodes.h>
#include <nodes/pg_list.h>

void ts_show_scan_qual(List *qual, const char *qlabel, PlanState *planstate, List *ancestors,
ExplainState *es);

void ts_show_instrumentation_count(const char *qlabel, int which, PlanState *planstate,
ExplainState *es);
3 changes: 2 additions & 1 deletion tsl/src/nodes/decompress_chunk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/decompress_chunk.c
${CMAKE_CURRENT_SOURCE_DIR}/exec.c
${CMAKE_CURRENT_SOURCE_DIR}/planner.c
${CMAKE_CURRENT_SOURCE_DIR}/qual_pushdown.c)
${CMAKE_CURRENT_SOURCE_DIR}/qual_pushdown.c
${CMAKE_CURRENT_SOURCE_DIR}/vector_predicates.c)
target_sources(${TSL_LIBRARY_NAME} PRIVATE ${SOURCES})
1 change: 1 addition & 0 deletions tsl/src/nodes/decompress_chunk/batch_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ batch_array_free_at(DecompressChunkState *chunk_state, int batch_index)
/* Reset batch state */
batch_state->total_batch_rows = 0;
batch_state->next_batch_row = 0;
batch_state->vector_qual_result = NULL;

if (batch_state->per_batch_context != NULL)
{
Expand Down
Loading