From ce4e16b13243f468604f0c6d75289a1b793ac1e0 Mon Sep 17 00:00:00 2001 From: mkaruza Date: Wed, 8 May 2024 09:36:54 +0200 Subject: [PATCH] Release memory that was allocated in result tuple / TIMESTAMP filter * Memory allocated columns needs to be released for each result tuple * Filter for TIMESTAMP --- src/quack_filter.cpp | 5 +++++ src/quack_node.cpp | 10 +++++++++- src/quack_types.cpp | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/quack_filter.cpp b/src/quack_filter.cpp index a0a85cb1..099cdb23 100644 --- a/src/quack_filter.cpp +++ b/src/quack_filter.cpp @@ -47,6 +47,11 @@ FilterOperationSwitch(Datum &value, duckdb::Value &constant, Oid typeOid) { return TemplatedFilterOperation(dateDatum, constant); break; } + case TIMESTAMPOID: { + Datum timeStampDatum = static_cast(value + quack::QUACK_DUCK_TIMESTAMP_OFFSET); + return TemplatedFilterOperation(timeStampDatum, constant); + break; + } default: elog(ERROR, "(DuckDB/FilterOperationSwitch) Unsupported quack type: %d", typeOid); } diff --git a/src/quack_node.cpp b/src/quack_node.cpp index 7cc4d3e4..ccb32e16 100644 --- a/src/quack_node.cpp +++ b/src/quack_node.cpp @@ -52,8 +52,9 @@ Quack_BeginCustomScan(CustomScanState *cscanstate, EState *estate, int eflags) { static TupleTableSlot * Quack_ExecCustomScan(CustomScanState *node) { QuackScanState *quackScanState = (QuackScanState *)node; - TupleTableSlot *slot = quackScanState->css.ss.ss_ScanTupleSlot; + MemoryContext oldContext; + if (!quackScanState->is_executed) { quackScanState->queryResult = quackScanState->preparedStatement->Execute(); @@ -66,13 +67,18 @@ Quack_ExecCustomScan(CustomScanState *node) { quackScanState->currentRow = 0; quackScanState->fetch_next = false; if (!quackScanState->currentDataChunk || quackScanState->currentDataChunk->size() == 0) { + MemoryContextReset(quackScanState->css.ss.ps.ps_ExprContext->ecxt_per_tuple_memory); ExecClearTuple(slot); return slot; } } + MemoryContextReset(quackScanState->css.ss.ps.ps_ExprContext->ecxt_per_tuple_memory); ExecClearTuple(slot); + /* MemoryContext used for allocation */ + oldContext = MemoryContextSwitchTo(quackScanState->css.ss.ps.ps_ExprContext->ecxt_per_tuple_memory); + for (idx_t col = 0; col < quackScanState->columnCount; col++) { auto value = quackScanState->currentDataChunk->GetValue(col, quackScanState->currentRow); if (value.IsNull()) { @@ -83,6 +89,8 @@ Quack_ExecCustomScan(CustomScanState *node) { } } + MemoryContextSwitchTo(oldContext); + quackScanState->currentRow++; if (quackScanState->currentRow >= quackScanState->currentDataChunk->size()) { delete quackScanState->currentDataChunk.release(); diff --git a/src/quack_types.cpp b/src/quack_types.cpp index bacb3773..34ca106a 100644 --- a/src/quack_types.cpp +++ b/src/quack_types.cpp @@ -111,6 +111,8 @@ GetPostgresDuckDBType(duckdb::LogicalTypeId type) { return INT4OID; case duckdb::LogicalTypeId::BIGINT: return INT8OID; + case duckdb::LogicalTypeId::HUGEINT: + return NUMERICOID; case duckdb::LogicalTypeId::VARCHAR: return VARCHAROID; case duckdb::LogicalTypeId::DATE: