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

[columnar] Force trigger and constraint checks after every multi-insert #182

Merged
merged 1 commit into from
Oct 27, 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
3 changes: 1 addition & 2 deletions columnar/src/backend/columnar/columnar_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ static void InsertTupleAndEnforceConstraints(ModifyState *state, Datum *values,
bool *nulls);
static void DeleteTupleAndEnforceConstraints(ModifyState *state, HeapTuple heapTuple);
static void FinishModifyRelation(ModifyState *state);
static EState * create_estate_for_relation(Relation rel);
static bytea * DatumToBytea(Datum value, Form_pg_attribute attrForm);
static Datum ByteaToDatum(bytea *bytes, Form_pg_attribute attrForm);
static bool WriteColumnarOptions(Oid regclass, ColumnarOptions *options, bool overwrite);
Expand Down Expand Up @@ -2079,7 +2078,7 @@ FinishModifyRelation(ModifyState *state)
*
* This is based on similar code in copy.c
*/
static EState *
EState *
create_estate_for_relation(Relation rel)
{
EState *estate = CreateExecutorState();
Expand Down
28 changes: 28 additions & 0 deletions columnar/src/backend/columnar/columnar_tableam.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "commands/progress.h"
#include "commands/vacuum.h"
#include "commands/extension.h"
#include "commands/trigger.h"
#include "executor/executor.h"
#include "funcapi.h"
#include "nodes/makefuncs.h"
Expand Down Expand Up @@ -898,6 +899,33 @@ columnar_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples,

uint64 writtenRowNumber = ColumnarWriteRow(writeState, values,
tupleSlot->tts_isnull);

EState *estate = create_estate_for_relation(relation);

#if PG_VERSION_NUM >= PG_VERSION_14
ResultRelInfo *resultRelInfo = makeNode(ResultRelInfo);
InitResultRelInfo(resultRelInfo, relation, 1, NULL, 0);
#else
ResultRelInfo *resultRelInfo = estate->es_result_relation_info;
#endif

ExecOpenIndices(resultRelInfo, false);

if (relation->rd_att->constr)
ExecConstraints(resultRelInfo, tupleSlot, estate);

ExecCloseIndices(resultRelInfo);

AfterTriggerEndQuery(estate);
#if PG_VERSION_NUM >= PG_VERSION_14
ExecCloseResultRelations(estate);
ExecCloseRangeTableRelations(estate);
#else
ExecCleanUpTriggerState(estate);
#endif
ExecResetTupleTable(estate->es_tupleTable, false);
FreeExecutorState(estate);

tupleSlot->tts_tid = row_number_to_tid(writtenRowNumber);

MemoryContextReset(ColumnarWritePerTupleContext(writeState));
Expand Down
1 change: 1 addition & 0 deletions columnar/src/include/columnar/columnar.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ extern bytea * ReadChunkRowMask(RelFileNode relfilenode, Snapshot snapshot,
MemoryContext ctx,
uint64 stripeFirstRowNumber, int rowCount);
extern Datum create_table_row_mask(PG_FUNCTION_ARGS);
extern EState * create_estate_for_relation(Relation rel);

/* columnar_planner_hook.c */
extern void columnar_planner_init(void);
Expand Down