Skip to content
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
10 changes: 10 additions & 0 deletions src/include/duckdb/main/client_context_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "duckdb/common/optional_ptr.hpp"
#include "duckdb/main/config.hpp"
#include "duckdb/main/valid_checker.hpp"
#include "duckdb/planner/expression/bound_parameter_data.hpp"
#include "duckdb/transaction/meta_transaction.hpp"
#include "duckdb/transaction/transaction_manager.hpp"
#include "duckdb/main/database_manager.hpp"
Expand All @@ -39,6 +40,11 @@ struct PreparedStatementCallbackInfo {
const PendingQueryParameters &parameters;
};

struct BindPreparedStatementCallbackInfo {
PreparedStatementData &prepared_statement;
optional_ptr<case_insensitive_map_t<BoundParameterData>> parameters;
};

//! ClientContextState is virtual base class for ClientContext-local (or Query-Local, using QueryEnd callback) state
//! e.g. caches that need to live as long as a ClientContext or Query.
class ClientContextState {
Expand Down Expand Up @@ -78,6 +84,10 @@ class ClientContextState {
RebindQueryInfo current_rebind) {
return RebindQueryInfo::DO_NOT_REBIND;
}
virtual RebindQueryInfo OnRebindPreparedStatement(ClientContext &context, BindPreparedStatementCallbackInfo &info,
RebindQueryInfo current_rebind) {
return RebindQueryInfo::DO_NOT_REBIND;
}
virtual void WriteProfilingInformation(std::ostream &ss) {
}

Expand Down
13 changes: 12 additions & 1 deletion src/planner/binder/statement/bind_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,18 @@ BoundStatement Binder::Bind(ExecuteStatement &stmt) {
}
unique_ptr<LogicalOperator> rebound_plan;

if (prepared->RequireRebind(context, &bind_values)) {
RebindQueryInfo rebind = RebindQueryInfo::DO_NOT_REBIND;
if (prepared->RequireRebind(context, bind_values)) {
rebind = RebindQueryInfo::ATTEMPT_TO_REBIND;
}
for (auto &state : context.registered_state->States()) {
BindPreparedStatementCallbackInfo info {*prepared, bind_values};
auto new_rebind = state->OnRebindPreparedStatement(context, info, rebind);
if (new_rebind == RebindQueryInfo::ATTEMPT_TO_REBIND) {
rebind = RebindQueryInfo::ATTEMPT_TO_REBIND;
}
}
if (rebind == RebindQueryInfo::ATTEMPT_TO_REBIND) {
// catalog was modified or statement does not have clear types: rebind the statement before running the execute
Planner prepared_planner(context);
prepared_planner.parameter_data = bind_values;
Expand Down
Loading