Skip to content

Commit

Permalink
[columnar] Force trigger and constraint checks after every multi-inse…
Browse files Browse the repository at this point in the history
…rt (#182)
  • Loading branch information
JerrySievert authored Oct 27, 2023
1 parent 84b337c commit 5dc546e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
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

0 comments on commit 5dc546e

Please sign in to comment.