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
2 changes: 2 additions & 0 deletions .unreleased/pr_8336
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixes: #8336 Fix generic plans for FK checks and prepared statements
Thanks: @CodeTherapist for reporting the issue with FK checks not working after several insert statements
13 changes: 9 additions & 4 deletions src/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <utils/builtins.h>
#include <utils/datum.h>
#include <utils/hsearch.h>
#include <utils/inval.h>
#include <utils/lsyscache.h>
#include <utils/palloc.h>
#include <utils/syscache.h>
Expand Down Expand Up @@ -3452,13 +3453,17 @@ ts_chunk_set_partial(Chunk *chunk)
Assert(ts_chunk_is_compressed(chunk));
set_status = ts_chunk_add_status(chunk, CHUNK_STATUS_COMPRESSED_PARTIAL);

/*
* If the status was set then convert the corresponding
* _timescaledb_catalog.chunk_column_stats entries "INVALID".
*/
if (set_status)
{
/*
* If the status was set then convert the corresponding
* _timescaledb_catalog.chunk_column_stats entries "INVALID".
*/
ts_chunk_column_stats_set_invalid(chunk->fd.hypertable_id, chunk->fd.id);

/* changed chunk status, so invalidate plans involving this chunk */
CacheInvalidateRelcacheByRelid(chunk->table_id);
}
return set_status;
}

Expand Down
3 changes: 0 additions & 3 deletions src/nodes/chunk_dispatch/chunk_insert_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <rewrite/rewriteManip.h>
#include <utils/builtins.h>
#include <utils/guc.h>
#include <utils/inval.h>
#include <utils/lsyscache.h>
#include <utils/memutils.h>
#include <utils/rel.h>
Expand Down Expand Up @@ -590,8 +589,6 @@ ts_chunk_insert_state_destroy(ChunkInsertState *state)
Oid chunk_relid = RelationGetRelid(state->result_relation_info->ri_RelationDesc);
Chunk *chunk = ts_chunk_get_by_relid(chunk_relid, true);
ts_chunk_set_partial(chunk);
/* changed chunk status, so invalidate any plans involving this chunk */
CacheInvalidateRelcacheByRelid(chunk_relid);
}

if (rri->ri_FdwRoutine && !rri->ri_usesFdwDirectModify && rri->ri_FdwRoutine->EndForeignModify)
Expand Down
12 changes: 7 additions & 5 deletions src/planner/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <optimizer/planner.h>
#include <optimizer/restrictinfo.h>
#include <optimizer/tlist.h>
#include <parser/parse_param.h>
#include <parser/parse_relation.h>
#include <parser/parsetree.h>
#include <utils/elog.h>
Expand Down Expand Up @@ -495,8 +496,8 @@ preprocess_fk_checks(Query *query, Cache *hcache, PreprocessQueryContext *contex
* DELETE FROM [ONLY] <fktable> WHERE $1 = fkatt1 [AND ...]
*/
if (query->commandType == CMD_DELETE && list_length(query->rtable) == 1 &&
context->root->glob->boundParams && query->jointree->quals &&
IsA(query->jointree->quals, OpExpr))
query->jointree->quals && IsA(query->jointree->quals, OpExpr) &&
(context->root->glob->boundParams || query_contains_extern_params(query)))
{
RangeTblEntry *rte = linitial_node(RangeTblEntry, query->rtable);
if (!rte->inh && rte->rtekind == RTE_RELATION)
Expand All @@ -517,8 +518,8 @@ preprocess_fk_checks(Query *query, Cache *hcache, PreprocessQueryContext *contex
* WHERE $n = fkatt1 [AND ...]
*/
if (query->commandType == CMD_UPDATE && list_length(query->rtable) == 1 &&
context->root->glob->boundParams && query->jointree->quals &&
IsA(query->jointree->quals, OpExpr))
query->jointree->quals && IsA(query->jointree->quals, OpExpr) &&
(context->root->glob->boundParams || query_contains_extern_params(query)))
{
RangeTblEntry *rte = linitial_node(RangeTblEntry, query->rtable);
if (!rte->inh && rte->rtekind == RTE_RELATION)
Expand All @@ -540,7 +541,8 @@ preprocess_fk_checks(Query *query, Cache *hcache, PreprocessQueryContext *contex
* FOR KEY SHARE OF x
*/
if (query->commandType == CMD_SELECT && query->hasForUpdate &&
list_length(query->rtable) == 1 && context->root->glob->boundParams)
list_length(query->rtable) == 1 &&
(context->root->glob->boundParams || query_contains_extern_params(query)))
{
RangeTblEntry *rte = linitial_node(RangeTblEntry, query->rtable);
if (!rte->inh && rte->rtekind == RTE_RELATION && rte->rellockmode == RowShareLock &&
Expand Down
Loading
Loading