Skip to content
Open
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
4 changes: 2 additions & 2 deletions fts/src/function/query_fts_bind_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void QueryFTSOptionalParams::evaluateParams(main::ClientContext* context) {
std::vector<std::string> QueryFTSBindData::getQueryTerms(main::ClientContext& context) const {
auto queryInStr =
ExpressionUtil::evaluateLiteral<std::string>(&context, query, LogicalType::STRING());
auto config = entry.getAuxInfo().cast<FTSIndexAuxInfo>().config;
auto config = auxInfo.config;
FTSUtils::normalizeQuery(queryInStr, config.ignorePatternQuery,
true /* protectWildcardChars */);
auto terms = FTSUtils::tokenizeString(queryInStr, config);
Expand All @@ -57,7 +57,7 @@ std::vector<std::string> QueryFTSBindData::getQueryTerms(main::ClientContext& co
config.stopWordsTableName)
->getTableID())
->ptrCast<NodeTable>();
return FTSUtils::stemTerms(terms, entry.getAuxInfo().cast<FTSIndexAuxInfo>().config,
return FTSUtils::stemTerms(terms, auxInfo.config,
MemoryManager::Get(context), stopWordsTable, transaction::Transaction::Get(context),
optionalParams->constCast<QueryFTSOptionalParams>().conjunctive.getParamVal(),
true /* isQuery */);
Expand Down
5 changes: 3 additions & 2 deletions fts/src/function/query_fts_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void QFTSOutputWriter::write(processor::FactorizedTable& scoreFT, nodeID_t docNo
scoreInfo.scoreData.size() != numUniqueTerms) {
return;
}
auto auxInfo = bindData.entry.getAuxInfo().cast<FTSIndexAuxInfo>();
auto auxInfo = bindData.auxInfo;
for (auto& scoreData : scoreInfo.scoreData) {
auto numDocs = bindData.numDocs;
auto avgDocLen = bindData.avgDocLen;
Expand Down Expand Up @@ -492,7 +492,8 @@ static std::unique_ptr<TableFuncBindData> bindFunc(main::ClientContext* context,
auto& ftsIndex = index.value()->cast<FTSIndex>();
auto [numDocs, avgDocLen] = ftsIndex.getStats(transaction);
auto bindData = std::make_unique<QueryFTSBindData>(std::move(columns), std::move(graphEntry),
nodeOutput, std::move(query), *ftsIndexEntry,
nodeOutput, std::move(query),
ftsIndexEntry->getAuxInfo().cast<FTSIndexAuxInfo>(),
std::make_unique<QueryFTSOptionalParams>(input->optionalParamsLegacy), numDocs, avgDocLen);
context->setUseInternalCatalogEntry(false /* useInternalCatalogEntry */);
return bindData;
Expand Down
14 changes: 9 additions & 5 deletions fts/src/include/function/query_fts_bind_data.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "binder/expression/node_expression.h"
#include "catalog/catalog_entry/index_catalog_entry.h"
#include "catalog/fts_index_catalog_entry.h"
#include "function/fts_config.h"
#include "function/gds/gds.h"

Expand Down Expand Up @@ -31,18 +31,22 @@ struct QueryFTSOptionalParams : public function::OptionalParams {

struct QueryFTSBindData final : public function::GDSBindData {
std::shared_ptr<binder::Expression> query;
const catalog::IndexCatalogEntry& entry;
// Owned copy of the FTS aux info. This must NOT be a reference/pointer into the
// catalog: bind data outlives the bind transaction (prepared-plan cache reuses it
// across executions on the same connection), so a catalog reference dangles on the
// second execution and segfaults (see issue #1082).
FTSIndexAuxInfo auxInfo;
common::table_id_t outputTableID;
common::idx_t numDocs;
double avgDocLen;

QueryFTSBindData(binder::expression_vector columns, graph::NativeGraphEntry graphEntry,
std::shared_ptr<binder::Expression> docs, std::shared_ptr<binder::Expression> query,
const catalog::IndexCatalogEntry& entry,
const FTSIndexAuxInfo& auxInfo,
std::unique_ptr<QueryFTSOptionalParams> optionalParams, common::idx_t numDocs,
double avgDocLen)
: GDSBindData{std::move(columns), std::move(graphEntry), binder::expression_vector{docs}},
query{std::move(query)}, entry{entry},
query{std::move(query)}, auxInfo{auxInfo},
outputTableID{output[0]->constCast<binder::NodeExpression>().getTableIDs()[0]},
numDocs{numDocs}, avgDocLen{avgDocLen} {
auto& nodeExpr = output[0]->constCast<binder::NodeExpression>();
Expand All @@ -51,7 +55,7 @@ struct QueryFTSBindData final : public function::GDSBindData {
this->optionalParams = std::move(optionalParams);
}
QueryFTSBindData(const QueryFTSBindData& other)
: GDSBindData{other}, query{other.query}, entry{other.entry},
: GDSBindData{other}, query{other.query}, auxInfo{other.auxInfo},
outputTableID{other.outputTableID}, numDocs{other.numDocs}, avgDocLen{other.avgDocLen} {}

std::vector<std::string> getQueryTerms(main::ClientContext& context) const;
Expand Down
Loading