diff --git a/src/backend/columnar/cstore.c b/src/backend/columnar/cstore.c index 75d768fc8..be27ee9a0 100644 --- a/src/backend/columnar/cstore.c +++ b/src/backend/columnar/cstore.c @@ -35,12 +35,12 @@ #define DEFAULT_COMPRESSION_TYPE COMPRESSION_PG_LZ #endif -int cstore_compression = DEFAULT_COMPRESSION_TYPE; -int cstore_stripe_row_count = DEFAULT_STRIPE_ROW_COUNT; -int cstore_chunk_row_count = DEFAULT_CHUNK_ROW_COUNT; +int columnar_compression = DEFAULT_COMPRESSION_TYPE; +int columnar_stripe_row_count = DEFAULT_STRIPE_ROW_COUNT; +int columnar_chunk_row_count = DEFAULT_CHUNK_ROW_COUNT; int columnar_compression_level = 3; -static const struct config_enum_entry cstore_compression_options[] = +static const struct config_enum_entry columnar_compression_options[] = { { "none", COMPRESSION_NONE, false }, { "pglz", COMPRESSION_PG_LZ, false }, @@ -54,14 +54,14 @@ static const struct config_enum_entry cstore_compression_options[] = }; void -cstore_init() +columnar_init_gucs() { DefineCustomEnumVariable("columnar.compression", "Compression type for cstore.", NULL, - &cstore_compression, + &columnar_compression, DEFAULT_COMPRESSION_TYPE, - cstore_compression_options, + columnar_compression_options, PGC_USERSET, 0, NULL, @@ -84,7 +84,7 @@ cstore_init() DefineCustomIntVariable("columnar.stripe_row_count", "Maximum number of tuples per stripe.", NULL, - &cstore_stripe_row_count, + &columnar_stripe_row_count, DEFAULT_STRIPE_ROW_COUNT, STRIPE_ROW_COUNT_MINIMUM, STRIPE_ROW_COUNT_MAXIMUM, @@ -97,7 +97,7 @@ cstore_init() DefineCustomIntVariable("columnar.chunk_row_count", "Maximum number of rows per chunk.", NULL, - &cstore_chunk_row_count, + &columnar_chunk_row_count, DEFAULT_CHUNK_ROW_COUNT, CHUNK_ROW_COUNT_MINIMUM, CHUNK_ROW_COUNT_MAXIMUM, @@ -120,13 +120,13 @@ ParseCompressionType(const char *compressionTypeString) Assert(compressionTypeString != NULL); for (int compressionIndex = 0; - cstore_compression_options[compressionIndex].name != NULL; + columnar_compression_options[compressionIndex].name != NULL; compressionIndex++) { - const char *compressionName = cstore_compression_options[compressionIndex].name; + const char *compressionName = columnar_compression_options[compressionIndex].name; if (strncmp(compressionTypeString, compressionName, NAMEDATALEN) == 0) { - return cstore_compression_options[compressionIndex].val; + return columnar_compression_options[compressionIndex].val; } } @@ -143,14 +143,14 @@ const char * CompressionTypeStr(CompressionType requestedType) { for (int compressionIndex = 0; - cstore_compression_options[compressionIndex].name != NULL; + columnar_compression_options[compressionIndex].name != NULL; compressionIndex++) { CompressionType compressionType = - cstore_compression_options[compressionIndex].val; + columnar_compression_options[compressionIndex].val; if (compressionType == requestedType) { - return cstore_compression_options[compressionIndex].name; + return columnar_compression_options[compressionIndex].name; } } diff --git a/src/backend/columnar/cstore_customscan.c b/src/backend/columnar/cstore_customscan.c index e8117a070..88754a09e 100644 --- a/src/backend/columnar/cstore_customscan.c +++ b/src/backend/columnar/cstore_customscan.c @@ -1,6 +1,6 @@ /*------------------------------------------------------------------------- * - * cstore_customscan.c + * columnar_customscan.c * * This file contains the implementation of a postgres custom scan that * we use to push down the projections into the table access methods. @@ -29,83 +29,86 @@ #include "columnar/cstore_customscan.h" #include "columnar/cstore_tableam.h" -typedef struct CStoreScanPath +typedef struct ColumnarScanPath { CustomPath custom_path; /* place for local state during planning */ -} CStoreScanPath; +} ColumnarScanPath; -typedef struct CStoreScanScan +typedef struct ColumnarScanScan { CustomScan custom_scan; /* place for local state during execution */ -} CStoreScanScan; +} ColumnarScanScan; -typedef struct CStoreScanState +typedef struct ColumnarScanState { CustomScanState custom_scanstate; List *qual; -} CStoreScanState; +} ColumnarScanState; -static void CStoreSetRelPathlistHook(PlannerInfo *root, RelOptInfo *rel, Index rti, - RangeTblEntry *rte); -static Path * CreateCStoreScanPath(RelOptInfo *rel, RangeTblEntry *rte); -static Cost CStoreScanCost(RangeTblEntry *rte); -static Plan * CStoreScanPath_PlanCustomPath(PlannerInfo *root, - RelOptInfo *rel, - struct CustomPath *best_path, - List *tlist, - List *clauses, - List *custom_plans); +static void ColumnarSetRelPathlistHook(PlannerInfo *root, RelOptInfo *rel, Index rti, + RangeTblEntry *rte); +static Path * CreateColumnarScanPath(RelOptInfo *rel, RangeTblEntry *rte); +static Cost ColumnarScanCost(RangeTblEntry *rte); +static Plan * ColumnarScanPath_PlanCustomPath(PlannerInfo *root, + RelOptInfo *rel, + struct CustomPath *best_path, + List *tlist, + List *clauses, + List *custom_plans); -static Node * CStoreScan_CreateCustomScanState(CustomScan *cscan); +static Node * ColumnarScan_CreateCustomScanState(CustomScan *cscan); -static void CStoreScan_BeginCustomScan(CustomScanState *node, EState *estate, int eflags); -static TupleTableSlot * CStoreScan_ExecCustomScan(CustomScanState *node); -static void CStoreScan_EndCustomScan(CustomScanState *node); -static void CStoreScan_ReScanCustomScan(CustomScanState *node); +static void ColumnarScan_BeginCustomScan(CustomScanState *node, EState *estate, int + eflags); +static TupleTableSlot * ColumnarScan_ExecCustomScan(CustomScanState *node); +static void ColumnarScan_EndCustomScan(CustomScanState *node); +static void ColumnarScan_ReScanCustomScan(CustomScanState *node); +static void ColumnarScan_ExplainCustomScan(CustomScanState *node, List *ancestors, + ExplainState *es); /* saved hook value in case of unload */ static set_rel_pathlist_hook_type PreviousSetRelPathlistHook = NULL; -static bool EnableCStoreCustomScan = true; +static bool EnableColumnarCustomScan = true; -const struct CustomPathMethods CStoreScanPathMethods = { +const struct CustomPathMethods ColumnarScanPathMethods = { .CustomName = "ColumnarScan", - .PlanCustomPath = CStoreScanPath_PlanCustomPath, + .PlanCustomPath = ColumnarScanPath_PlanCustomPath, }; -const struct CustomScanMethods CStoreScanScanMethods = { +const struct CustomScanMethods ColumnarScanScanMethods = { .CustomName = "ColumnarScan", - .CreateCustomScanState = CStoreScan_CreateCustomScanState, + .CreateCustomScanState = ColumnarScan_CreateCustomScanState, }; -const struct CustomExecMethods CStoreExecuteMethods = { +const struct CustomExecMethods ColumnarExecuteMethods = { .CustomName = "ColumnarScan", - .BeginCustomScan = CStoreScan_BeginCustomScan, - .ExecCustomScan = CStoreScan_ExecCustomScan, - .EndCustomScan = CStoreScan_EndCustomScan, - .ReScanCustomScan = CStoreScan_ReScanCustomScan, + .BeginCustomScan = ColumnarScan_BeginCustomScan, + .ExecCustomScan = ColumnarScan_ExecCustomScan, + .EndCustomScan = ColumnarScan_EndCustomScan, + .ReScanCustomScan = ColumnarScan_ReScanCustomScan, - .ExplainCustomScan = NULL, + .ExplainCustomScan = ColumnarScan_ExplainCustomScan, }; /* - * cstore_customscan_init installs the hook required to intercept the postgres planner and + * columnar_customscan_init installs the hook required to intercept the postgres planner and * provide extra paths for cstore tables */ void -cstore_customscan_init() +columnar_customscan_init() { PreviousSetRelPathlistHook = set_rel_pathlist_hook; - set_rel_pathlist_hook = CStoreSetRelPathlistHook; + set_rel_pathlist_hook = ColumnarSetRelPathlistHook; /* register customscan specific GUC's */ DefineCustomBoolVariable( @@ -113,7 +116,7 @@ cstore_customscan_init() gettext_noop("Enables the use of a custom scan to push projections and quals " "into the storage layer"), NULL, - &EnableCStoreCustomScan, + &EnableColumnarCustomScan, true, PGC_USERSET, GUC_NO_SHOW_ALL, @@ -133,8 +136,8 @@ clear_paths(RelOptInfo *rel) static void -CStoreSetRelPathlistHook(PlannerInfo *root, RelOptInfo *rel, Index rti, - RangeTblEntry *rte) +ColumnarSetRelPathlistHook(PlannerInfo *root, RelOptInfo *rel, Index rti, + RangeTblEntry *rte) { /* call into previous hook if assigned */ if (PreviousSetRelPathlistHook) @@ -142,7 +145,7 @@ CStoreSetRelPathlistHook(PlannerInfo *root, RelOptInfo *rel, Index rti, PreviousSetRelPathlistHook(root, rel, rti, rte); } - if (!EnableCStoreCustomScan) + if (!EnableColumnarCustomScan) { /* custon scans are disabled, use normal table access method api instead */ return; @@ -168,7 +171,7 @@ CStoreSetRelPathlistHook(PlannerInfo *root, RelOptInfo *rel, Index rti, errmsg("sample scans not supported on columnar tables"))); } - Path *customPath = CreateCStoreScanPath(rel, rte); + Path *customPath = CreateColumnarScanPath(rel, rte); ereport(DEBUG1, (errmsg("pathlist hook for cstore table am"))); @@ -181,16 +184,16 @@ CStoreSetRelPathlistHook(PlannerInfo *root, RelOptInfo *rel, Index rti, static Path * -CreateCStoreScanPath(RelOptInfo *rel, RangeTblEntry *rte) +CreateColumnarScanPath(RelOptInfo *rel, RangeTblEntry *rte) { - CStoreScanPath *cspath = (CStoreScanPath *) newNode(sizeof(CStoreScanPath), - T_CustomPath); + ColumnarScanPath *cspath = (ColumnarScanPath *) newNode(sizeof(ColumnarScanPath), + T_CustomPath); /* * popuate custom path information */ CustomPath *cpath = &cspath->custom_path; - cpath->methods = &CStoreScanPathMethods; + cpath->methods = &ColumnarScanPathMethods; /* * populate generic path information @@ -206,19 +209,19 @@ CreateCStoreScanPath(RelOptInfo *rel, RangeTblEntry *rte) */ path->rows = rel->rows; path->startup_cost = 0; - path->total_cost = path->startup_cost + CStoreScanCost(rte); + path->total_cost = path->startup_cost + ColumnarScanCost(rte); return (Path *) cspath; } /* - * CStoreScanCost calculates the cost of scanning the cstore table. The cost is estimated + * ColumnarScanCost calculates the cost of scanning the cstore table. The cost is estimated * by using all stripe metadata to estimate based on the columns to read how many pages * need to be read. */ static Cost -CStoreScanCost(RangeTblEntry *rte) +ColumnarScanCost(RangeTblEntry *rte) { Relation rel = RelationIdGetRelation(rte->relid); List *stripeList = StripesForRelfilenode(rel->rd_node); @@ -247,18 +250,18 @@ CStoreScanCost(RangeTblEntry *rte) static Plan * -CStoreScanPath_PlanCustomPath(PlannerInfo *root, - RelOptInfo *rel, - struct CustomPath *best_path, - List *tlist, - List *clauses, - List *custom_plans) +ColumnarScanPath_PlanCustomPath(PlannerInfo *root, + RelOptInfo *rel, + struct CustomPath *best_path, + List *tlist, + List *clauses, + List *custom_plans) { - CStoreScanScan *plan = (CStoreScanScan *) newNode(sizeof(CStoreScanScan), - T_CustomScan); + ColumnarScanScan *plan = (ColumnarScanScan *) newNode(sizeof(ColumnarScanScan), + T_CustomScan); CustomScan *cscan = &plan->custom_scan; - cscan->methods = &CStoreScanScanMethods; + cscan->methods = &ColumnarScanScanMethods; /* Reduce RestrictInfo list to bare expressions; ignore pseudoconstants */ clauses = extract_actual_clauses(clauses, false); @@ -272,13 +275,13 @@ CStoreScanPath_PlanCustomPath(PlannerInfo *root, static Node * -CStoreScan_CreateCustomScanState(CustomScan *cscan) +ColumnarScan_CreateCustomScanState(CustomScan *cscan) { - CStoreScanState *cstorescanstate = (CStoreScanState *) newNode( - sizeof(CStoreScanState), T_CustomScanState); + ColumnarScanState *cstorescanstate = (ColumnarScanState *) newNode( + sizeof(ColumnarScanState), T_CustomScanState); CustomScanState *cscanstate = &cstorescanstate->custom_scanstate; - cscanstate->methods = &CStoreExecuteMethods; + cscanstate->methods = &ColumnarExecuteMethods; cstorescanstate->qual = cscan->scan.plan.qual; @@ -287,14 +290,14 @@ CStoreScan_CreateCustomScanState(CustomScan *cscan) static void -CStoreScan_BeginCustomScan(CustomScanState *cscanstate, EState *estate, int eflags) +ColumnarScan_BeginCustomScan(CustomScanState *cscanstate, EState *estate, int eflags) { /* scan slot is already initialized */ } static Bitmapset * -CStoreAttrNeeded(ScanState *ss) +ColumnarAttrNeeded(ScanState *ss) { TupleTableSlot *slot = ss->ss_ScanTupleSlot; int natts = slot->tts_tupleDescriptor->natts; @@ -335,7 +338,7 @@ CStoreAttrNeeded(ScanState *ss) static TupleTableSlot * -CStoreScanNext(CStoreScanState *cstorescanstate) +ColumnarScanNext(ColumnarScanState *cstorescanstate) { CustomScanState *node = (CustomScanState *) cstorescanstate; @@ -351,16 +354,16 @@ CStoreScanNext(CStoreScanState *cstorescanstate) { /* the cstore access method does not use the flags, they are specific to heap */ uint32 flags = 0; - Bitmapset *attr_needed = CStoreAttrNeeded(&node->ss); + Bitmapset *attr_needed = ColumnarAttrNeeded(&node->ss); /* * We reach here if the scan is not parallel, or if we're serially * executing a scan that was planned to be parallel. */ - scandesc = cstore_beginscan_extended(node->ss.ss_currentRelation, - estate->es_snapshot, - 0, NULL, NULL, flags, attr_needed, - cstorescanstate->qual); + scandesc = columnar_beginscan_extended(node->ss.ss_currentRelation, + estate->es_snapshot, + 0, NULL, NULL, flags, attr_needed, + cstorescanstate->qual); bms_free(attr_needed); node->ss.ss_currentScanDesc = scandesc; @@ -381,23 +384,23 @@ CStoreScanNext(CStoreScanState *cstorescanstate) * SeqRecheck -- access method routine to recheck a tuple in EvalPlanQual */ static bool -CStoreScanRecheck(CStoreScanState *node, TupleTableSlot *slot) +ColumnarScanRecheck(ColumnarScanState *node, TupleTableSlot *slot) { return true; } static TupleTableSlot * -CStoreScan_ExecCustomScan(CustomScanState *node) +ColumnarScan_ExecCustomScan(CustomScanState *node) { return ExecScan(&node->ss, - (ExecScanAccessMtd) CStoreScanNext, - (ExecScanRecheckMtd) CStoreScanRecheck); + (ExecScanAccessMtd) ColumnarScanNext, + (ExecScanRecheckMtd) ColumnarScanRecheck); } static void -CStoreScan_EndCustomScan(CustomScanState *node) +ColumnarScan_EndCustomScan(CustomScanState *node) { /* * get information from node @@ -429,7 +432,7 @@ CStoreScan_EndCustomScan(CustomScanState *node) static void -CStoreScan_ReScanCustomScan(CustomScanState *node) +ColumnarScan_ReScanCustomScan(CustomScanState *node) { TableScanDesc scanDesc = node->ss.ss_currentScanDesc; if (scanDesc != NULL) @@ -439,4 +442,19 @@ CStoreScan_ReScanCustomScan(CustomScanState *node) } +static void +ColumnarScan_ExplainCustomScan(CustomScanState *node, List *ancestors, + ExplainState *es) +{ + TableScanDesc scanDesc = node->ss.ss_currentScanDesc; + + if (scanDesc != NULL) + { + int64 chunksFiltered = ColumnarGetChunksFiltered(scanDesc); + ExplainPropertyInteger("Columnar Chunks Removed by Filter", NULL, + chunksFiltered, es); + } +} + + #endif /* HAS_TABLEAM */ diff --git a/src/backend/columnar/cstore_metadata_tables.c b/src/backend/columnar/cstore_metadata_tables.c index 331b37319..f100ab9bb 100644 --- a/src/backend/columnar/cstore_metadata_tables.c +++ b/src/backend/columnar/cstore_metadata_tables.c @@ -1,6 +1,6 @@ /*------------------------------------------------------------------------- * - * cstore_metadata_tables.c + * columnar_metadata_tables.c * * Copyright (c), Citus Data, Inc. * @@ -79,13 +79,13 @@ static void GetHighestUsedAddressAndId(uint64 storageId, uint64 *highestUsedAddress, uint64 *highestUsedId); static List * ReadDataFileStripeList(uint64 storageId, Snapshot snapshot); -static Oid CStoreStripesRelationId(void); -static Oid CStoreStripesIndexRelationId(void); +static Oid ColumnarStripeRelationId(void); +static Oid ColumnarStripeIndexRelationId(void); static Oid ColumnarOptionsRelationId(void); static Oid ColumnarOptionsIndexRegclass(void); -static Oid CStoreSkipNodesRelationId(void); -static Oid CStoreSkipNodesIndexRelationId(void); -static Oid CStoreNamespaceId(void); +static Oid ColumnarChunkRelationId(void); +static Oid ColumnarChunkIndexRelationId(void); +static Oid ColumnarNamespaceId(void); static ModifyState * StartModifyRelation(Relation rel); static void InsertTupleAndEnforceConstraints(ModifyState *state, Datum *values, bool *nulls); @@ -102,18 +102,18 @@ static bool WriteColumnarOptions(Oid regclass, ColumnarOptions *options, bool ov PG_FUNCTION_INFO_V1(columnar_relation_storageid); /* constants for columnar.options */ -#define Natts_cstore_options 5 -#define Anum_cstore_options_regclass 1 -#define Anum_cstore_options_chunk_row_count 2 -#define Anum_cstore_options_stripe_row_count 3 -#define Anum_cstore_options_compression_level 4 -#define Anum_cstore_options_compression 5 +#define Natts_columnar_options 5 +#define Anum_columnar_options_regclass 1 +#define Anum_columnar_options_chunk_row_count 2 +#define Anum_columnar_options_stripe_row_count 3 +#define Anum_columnar_options_compression_level 4 +#define Anum_columnar_options_compression 5 /* ---------------- * columnar.options definition. * ---------------- */ -typedef struct FormData_cstore_options +typedef struct FormData_columnar_options { Oid regclass; int32 chunk_row_count; @@ -123,37 +123,37 @@ typedef struct FormData_cstore_options #ifdef CATALOG_VARLEN /* variable-length fields start here */ #endif -} FormData_cstore_options; -typedef FormData_cstore_options *Form_cstore_options; +} FormData_columnar_options; +typedef FormData_columnar_options *Form_columnar_options; -/* constants for cstore_stripe */ -#define Natts_cstore_stripes 8 -#define Anum_cstore_stripes_storageid 1 -#define Anum_cstore_stripes_stripe 2 -#define Anum_cstore_stripes_file_offset 3 -#define Anum_cstore_stripes_data_length 4 -#define Anum_cstore_stripes_column_count 5 -#define Anum_cstore_stripes_chunk_count 6 -#define Anum_cstore_stripes_chunk_row_count 7 -#define Anum_cstore_stripes_row_count 8 +/* constants for columnar.stripe */ +#define Natts_columnar_stripe 8 +#define Anum_columnar_stripe_storageid 1 +#define Anum_columnar_stripe_stripe 2 +#define Anum_columnar_stripe_file_offset 3 +#define Anum_columnar_stripe_data_length 4 +#define Anum_columnar_stripe_column_count 5 +#define Anum_columnar_stripe_chunk_count 6 +#define Anum_columnar_stripe_chunk_row_count 7 +#define Anum_columnar_stripe_row_count 8 -/* constants for cstore_skipnodes */ -#define Natts_cstore_skipnodes 14 -#define Anum_cstore_skipnodes_storageid 1 -#define Anum_cstore_skipnodes_stripe 2 -#define Anum_cstore_skipnodes_attr 3 -#define Anum_cstore_skipnodes_chunk 4 -#define Anum_cstore_skipnodes_row_count 5 -#define Anum_cstore_skipnodes_minimum_value 6 -#define Anum_cstore_skipnodes_maximum_value 7 -#define Anum_cstore_skipnodes_value_stream_offset 8 -#define Anum_cstore_skipnodes_value_stream_length 9 -#define Anum_cstore_skipnodes_exists_stream_offset 10 -#define Anum_cstore_skipnodes_exists_stream_length 11 -#define Anum_cstore_skipnodes_value_compression_type 12 -#define Anum_cstore_skipnodes_value_compression_level 13 -#define Anum_cstore_skipnodes_value_decompressed_size 14 +/* constants for columnar.chunk */ +#define Natts_columnar_chunk 14 +#define Anum_columnar_chunk_storageid 1 +#define Anum_columnar_chunk_stripe 2 +#define Anum_columnar_chunk_attr 3 +#define Anum_columnar_chunk_chunk 4 +#define Anum_columnar_chunk_row_count 5 +#define Anum_columnar_chunk_minimum_value 6 +#define Anum_columnar_chunk_maximum_value 7 +#define Anum_columnar_chunk_value_stream_offset 8 +#define Anum_columnar_chunk_value_stream_length 9 +#define Anum_columnar_chunk_exists_stream_offset 10 +#define Anum_columnar_chunk_exists_stream_length 11 +#define Anum_columnar_chunk_value_compression_type 12 +#define Anum_columnar_chunk_value_compression_level 13 +#define Anum_columnar_chunk_value_decompressed_size 14 /* @@ -173,9 +173,9 @@ InitColumnarOptions(Oid regclass) } ColumnarOptions defaultOptions = { - .chunkRowCount = cstore_chunk_row_count, - .stripeRowCount = cstore_stripe_row_count, - .compressionType = cstore_compression, + .chunkRowCount = columnar_chunk_row_count, + .stripeRowCount = columnar_stripe_row_count, + .compressionType = columnar_compression, .compressionLevel = columnar_compression_level }; @@ -214,8 +214,8 @@ WriteColumnarOptions(Oid regclass, ColumnarOptions *options, bool overwrite) bool written = false; - bool nulls[Natts_cstore_options] = { 0 }; - Datum values[Natts_cstore_options] = { + bool nulls[Natts_columnar_options] = { 0 }; + Datum values[Natts_columnar_options] = { ObjectIdGetDatum(regclass), Int32GetDatum(options->chunkRowCount), Int32GetDatum(options->stripeRowCount), @@ -225,7 +225,7 @@ WriteColumnarOptions(Oid regclass, ColumnarOptions *options, bool overwrite) NameData compressionName = { 0 }; namestrcpy(&compressionName, CompressionTypeStr(options->compressionType)); - values[Anum_cstore_options_compression - 1] = NameGetDatum(&compressionName); + values[Anum_columnar_options_compression - 1] = NameGetDatum(&compressionName); /* create heap tuple and insert into catalog table */ Relation columnarOptions = relation_open(ColumnarOptionsRelationId(), @@ -234,7 +234,8 @@ WriteColumnarOptions(Oid regclass, ColumnarOptions *options, bool overwrite) /* find existing item to perform update if exist */ ScanKeyData scanKey[1] = { 0 }; - ScanKeyInit(&scanKey[0], Anum_cstore_options_regclass, BTEqualStrategyNumber, F_OIDEQ, + ScanKeyInit(&scanKey[0], Anum_columnar_options_regclass, BTEqualStrategyNumber, + F_OIDEQ, ObjectIdGetDatum(regclass)); Relation index = index_open(ColumnarOptionsIndexRegclass(), AccessShareLock); @@ -248,11 +249,11 @@ WriteColumnarOptions(Oid regclass, ColumnarOptions *options, bool overwrite) { /* TODO check if the options are actually different, skip if not changed */ /* update existing record */ - bool update[Natts_cstore_options] = { 0 }; - update[Anum_cstore_options_chunk_row_count - 1] = true; - update[Anum_cstore_options_stripe_row_count - 1] = true; - update[Anum_cstore_options_compression_level - 1] = true; - update[Anum_cstore_options_compression - 1] = true; + bool update[Natts_columnar_options] = { 0 }; + update[Anum_columnar_options_chunk_row_count - 1] = true; + update[Anum_columnar_options_stripe_row_count - 1] = true; + update[Anum_columnar_options_compression_level - 1] = true; + update[Anum_columnar_options_compression - 1] = true; HeapTuple tuple = heap_modify_tuple(heapTuple, tupleDescriptor, values, nulls, update); @@ -303,7 +304,8 @@ DeleteColumnarTableOptions(Oid regclass, bool missingOk) /* find existing item to remove */ ScanKeyData scanKey[1] = { 0 }; - ScanKeyInit(&scanKey[0], Anum_cstore_options_regclass, BTEqualStrategyNumber, F_OIDEQ, + ScanKeyInit(&scanKey[0], Anum_columnar_options_regclass, BTEqualStrategyNumber, + F_OIDEQ, ObjectIdGetDatum(regclass)); Relation index = index_open(ColumnarOptionsIndexRegclass(), AccessShareLock); @@ -336,7 +338,8 @@ ReadColumnarOptions(Oid regclass, ColumnarOptions *options) { ScanKeyData scanKey[1]; - ScanKeyInit(&scanKey[0], Anum_cstore_options_regclass, BTEqualStrategyNumber, F_OIDEQ, + ScanKeyInit(&scanKey[0], Anum_columnar_options_regclass, BTEqualStrategyNumber, + F_OIDEQ, ObjectIdGetDatum(regclass)); Oid columnarOptionsOid = ColumnarOptionsRelationId(); @@ -365,7 +368,7 @@ ReadColumnarOptions(Oid regclass, ColumnarOptions *options) HeapTuple heapTuple = systable_getnext(scanDescriptor); if (HeapTupleIsValid(heapTuple)) { - Form_cstore_options tupOptions = (Form_cstore_options) GETSTRUCT(heapTuple); + Form_columnar_options tupOptions = (Form_columnar_options) GETSTRUCT(heapTuple); options->chunkRowCount = tupOptions->chunk_row_count; options->stripeRowCount = tupOptions->stripe_row_count; @@ -375,9 +378,9 @@ ReadColumnarOptions(Oid regclass, ColumnarOptions *options) else { /* populate options with system defaults */ - options->compressionType = cstore_compression; - options->stripeRowCount = cstore_stripe_row_count; - options->chunkRowCount = cstore_chunk_row_count; + options->compressionType = columnar_compression; + options->stripeRowCount = columnar_stripe_row_count; + options->chunkRowCount = columnar_chunk_row_count; options->compressionLevel = columnar_compression_level; } @@ -390,61 +393,61 @@ ReadColumnarOptions(Oid regclass, ColumnarOptions *options) /* - * SaveStripeSkipList saves StripeSkipList for a given stripe as rows - * of cstore_skipnodes. + * SaveStripeSkipList saves chunkList for a given stripe as rows + * of columnar.chunk. */ void -SaveStripeSkipList(RelFileNode relfilenode, uint64 stripe, StripeSkipList *stripeSkipList, +SaveStripeSkipList(RelFileNode relfilenode, uint64 stripe, StripeSkipList *chunkList, TupleDesc tupleDescriptor) { uint32 columnIndex = 0; uint32 chunkIndex = 0; - uint32 columnCount = stripeSkipList->columnCount; + uint32 columnCount = chunkList->columnCount; ColumnarMetapage *metapage = ReadMetapage(relfilenode, false); - Oid cstoreSkipNodesOid = CStoreSkipNodesRelationId(); - Relation cstoreSkipNodes = table_open(cstoreSkipNodesOid, RowExclusiveLock); - ModifyState *modifyState = StartModifyRelation(cstoreSkipNodes); + Oid columnarChunkOid = ColumnarChunkRelationId(); + Relation columnarChunk = table_open(columnarChunkOid, RowExclusiveLock); + ModifyState *modifyState = StartModifyRelation(columnarChunk); for (columnIndex = 0; columnIndex < columnCount; columnIndex++) { - for (chunkIndex = 0; chunkIndex < stripeSkipList->chunkCount; chunkIndex++) + for (chunkIndex = 0; chunkIndex < chunkList->chunkCount; chunkIndex++) { - ColumnChunkSkipNode *skipNode = - &stripeSkipList->chunkSkipNodeArray[columnIndex][chunkIndex]; + ColumnChunkSkipNode *chunk = + &chunkList->chunkSkipNodeArray[columnIndex][chunkIndex]; - Datum values[Natts_cstore_skipnodes] = { + Datum values[Natts_columnar_chunk] = { UInt64GetDatum(metapage->storageId), Int64GetDatum(stripe), Int32GetDatum(columnIndex + 1), Int32GetDatum(chunkIndex), - Int64GetDatum(skipNode->rowCount), + Int64GetDatum(chunk->rowCount), 0, /* to be filled below */ 0, /* to be filled below */ - Int64GetDatum(skipNode->valueChunkOffset), - Int64GetDatum(skipNode->valueLength), - Int64GetDatum(skipNode->existsChunkOffset), - Int64GetDatum(skipNode->existsLength), - Int32GetDatum(skipNode->valueCompressionType), - Int32GetDatum(skipNode->valueCompressionLevel), - Int64GetDatum(skipNode->decompressedValueSize) + Int64GetDatum(chunk->valueChunkOffset), + Int64GetDatum(chunk->valueLength), + Int64GetDatum(chunk->existsChunkOffset), + Int64GetDatum(chunk->existsLength), + Int32GetDatum(chunk->valueCompressionType), + Int32GetDatum(chunk->valueCompressionLevel), + Int64GetDatum(chunk->decompressedValueSize) }; - bool nulls[Natts_cstore_skipnodes] = { false }; + bool nulls[Natts_columnar_chunk] = { false }; - if (skipNode->hasMinMax) + if (chunk->hasMinMax) { - values[Anum_cstore_skipnodes_minimum_value - 1] = - PointerGetDatum(DatumToBytea(skipNode->minimumValue, + values[Anum_columnar_chunk_minimum_value - 1] = + PointerGetDatum(DatumToBytea(chunk->minimumValue, &tupleDescriptor->attrs[columnIndex])); - values[Anum_cstore_skipnodes_maximum_value - 1] = - PointerGetDatum(DatumToBytea(skipNode->maximumValue, + values[Anum_columnar_chunk_maximum_value - 1] = + PointerGetDatum(DatumToBytea(chunk->maximumValue, &tupleDescriptor->attrs[columnIndex])); } else { - nulls[Anum_cstore_skipnodes_minimum_value - 1] = true; - nulls[Anum_cstore_skipnodes_maximum_value - 1] = true; + nulls[Anum_columnar_chunk_minimum_value - 1] = true; + nulls[Anum_columnar_chunk_maximum_value - 1] = true; } InsertTupleAndEnforceConstraints(modifyState, values, nulls); @@ -452,14 +455,14 @@ SaveStripeSkipList(RelFileNode relfilenode, uint64 stripe, StripeSkipList *strip } FinishModifyRelation(modifyState); - table_close(cstoreSkipNodes, NoLock); + table_close(columnarChunk, NoLock); CommandCounterIncrement(); } /* - * ReadStripeSkipList fetches StripeSkipList for a given stripe. + * ReadStripeSkipList fetches chunk metadata for a given stripe. */ StripeSkipList * ReadStripeSkipList(RelFileNode relfilenode, uint64 stripe, TupleDesc tupleDescriptor, @@ -472,109 +475,109 @@ ReadStripeSkipList(RelFileNode relfilenode, uint64 stripe, TupleDesc tupleDescri ColumnarMetapage *metapage = ReadMetapage(relfilenode, false); - Oid cstoreSkipNodesOid = CStoreSkipNodesRelationId(); - Relation cstoreSkipNodes = table_open(cstoreSkipNodesOid, AccessShareLock); - Relation index = index_open(CStoreSkipNodesIndexRelationId(), AccessShareLock); + Oid columnarChunkOid = ColumnarChunkRelationId(); + Relation columnarChunk = table_open(columnarChunkOid, AccessShareLock); + Relation index = index_open(ColumnarChunkIndexRelationId(), AccessShareLock); - ScanKeyInit(&scanKey[0], Anum_cstore_skipnodes_storageid, + ScanKeyInit(&scanKey[0], Anum_columnar_chunk_storageid, BTEqualStrategyNumber, F_OIDEQ, UInt64GetDatum(metapage->storageId)); - ScanKeyInit(&scanKey[1], Anum_cstore_skipnodes_stripe, + ScanKeyInit(&scanKey[1], Anum_columnar_chunk_stripe, BTEqualStrategyNumber, F_OIDEQ, Int32GetDatum(stripe)); - SysScanDesc scanDescriptor = systable_beginscan_ordered(cstoreSkipNodes, index, NULL, + SysScanDesc scanDescriptor = systable_beginscan_ordered(columnarChunk, index, NULL, 2, scanKey); - StripeSkipList *skipList = palloc0(sizeof(StripeSkipList)); - skipList->chunkCount = chunkCount; - skipList->columnCount = columnCount; - skipList->chunkSkipNodeArray = palloc0(columnCount * sizeof(ColumnChunkSkipNode *)); + StripeSkipList *chunkList = palloc0(sizeof(StripeSkipList)); + chunkList->chunkCount = chunkCount; + chunkList->columnCount = columnCount; + chunkList->chunkSkipNodeArray = palloc0(columnCount * sizeof(ColumnChunkSkipNode *)); for (columnIndex = 0; columnIndex < columnCount; columnIndex++) { - skipList->chunkSkipNodeArray[columnIndex] = + chunkList->chunkSkipNodeArray[columnIndex] = palloc0(chunkCount * sizeof(ColumnChunkSkipNode)); } while (HeapTupleIsValid(heapTuple = systable_getnext(scanDescriptor))) { - Datum datumArray[Natts_cstore_skipnodes]; - bool isNullArray[Natts_cstore_skipnodes]; + Datum datumArray[Natts_columnar_chunk]; + bool isNullArray[Natts_columnar_chunk]; - heap_deform_tuple(heapTuple, RelationGetDescr(cstoreSkipNodes), datumArray, + heap_deform_tuple(heapTuple, RelationGetDescr(columnarChunk), datumArray, isNullArray); - int32 attr = DatumGetInt32(datumArray[Anum_cstore_skipnodes_attr - 1]); - int32 chunkIndex = DatumGetInt32(datumArray[Anum_cstore_skipnodes_chunk - 1]); + int32 attr = DatumGetInt32(datumArray[Anum_columnar_chunk_attr - 1]); + int32 chunkIndex = DatumGetInt32(datumArray[Anum_columnar_chunk_chunk - 1]); if (attr <= 0 || attr > columnCount) { - ereport(ERROR, (errmsg("invalid stripe skipnode entry"), + ereport(ERROR, (errmsg("invalid columnar chunk entry"), errdetail("Attribute number out of range: %d", attr))); } if (chunkIndex < 0 || chunkIndex >= chunkCount) { - ereport(ERROR, (errmsg("invalid stripe skipnode entry"), + ereport(ERROR, (errmsg("invalid columnar chunk entry"), errdetail("Chunk number out of range: %d", chunkIndex))); } columnIndex = attr - 1; - ColumnChunkSkipNode *skipNode = - &skipList->chunkSkipNodeArray[columnIndex][chunkIndex]; - skipNode->rowCount = DatumGetInt64(datumArray[Anum_cstore_skipnodes_row_count - - 1]); - skipNode->valueChunkOffset = - DatumGetInt64(datumArray[Anum_cstore_skipnodes_value_stream_offset - 1]); - skipNode->valueLength = - DatumGetInt64(datumArray[Anum_cstore_skipnodes_value_stream_length - 1]); - skipNode->existsChunkOffset = - DatumGetInt64(datumArray[Anum_cstore_skipnodes_exists_stream_offset - 1]); - skipNode->existsLength = - DatumGetInt64(datumArray[Anum_cstore_skipnodes_exists_stream_length - 1]); - skipNode->valueCompressionType = - DatumGetInt32(datumArray[Anum_cstore_skipnodes_value_compression_type - 1]); - skipNode->valueCompressionLevel = - DatumGetInt32(datumArray[Anum_cstore_skipnodes_value_compression_level - 1]); - skipNode->decompressedValueSize = - DatumGetInt64(datumArray[Anum_cstore_skipnodes_value_decompressed_size - 1]); + ColumnChunkSkipNode *chunk = + &chunkList->chunkSkipNodeArray[columnIndex][chunkIndex]; + chunk->rowCount = DatumGetInt64(datumArray[Anum_columnar_chunk_row_count - + 1]); + chunk->valueChunkOffset = + DatumGetInt64(datumArray[Anum_columnar_chunk_value_stream_offset - 1]); + chunk->valueLength = + DatumGetInt64(datumArray[Anum_columnar_chunk_value_stream_length - 1]); + chunk->existsChunkOffset = + DatumGetInt64(datumArray[Anum_columnar_chunk_exists_stream_offset - 1]); + chunk->existsLength = + DatumGetInt64(datumArray[Anum_columnar_chunk_exists_stream_length - 1]); + chunk->valueCompressionType = + DatumGetInt32(datumArray[Anum_columnar_chunk_value_compression_type - 1]); + chunk->valueCompressionLevel = + DatumGetInt32(datumArray[Anum_columnar_chunk_value_compression_level - 1]); + chunk->decompressedValueSize = + DatumGetInt64(datumArray[Anum_columnar_chunk_value_decompressed_size - 1]); - if (isNullArray[Anum_cstore_skipnodes_minimum_value - 1] || - isNullArray[Anum_cstore_skipnodes_maximum_value - 1]) + if (isNullArray[Anum_columnar_chunk_minimum_value - 1] || + isNullArray[Anum_columnar_chunk_maximum_value - 1]) { - skipNode->hasMinMax = false; + chunk->hasMinMax = false; } else { bytea *minValue = DatumGetByteaP( - datumArray[Anum_cstore_skipnodes_minimum_value - 1]); + datumArray[Anum_columnar_chunk_minimum_value - 1]); bytea *maxValue = DatumGetByteaP( - datumArray[Anum_cstore_skipnodes_maximum_value - 1]); + datumArray[Anum_columnar_chunk_maximum_value - 1]); - skipNode->minimumValue = + chunk->minimumValue = ByteaToDatum(minValue, &tupleDescriptor->attrs[columnIndex]); - skipNode->maximumValue = + chunk->maximumValue = ByteaToDatum(maxValue, &tupleDescriptor->attrs[columnIndex]); - skipNode->hasMinMax = true; + chunk->hasMinMax = true; } } systable_endscan_ordered(scanDescriptor); index_close(index, NoLock); - table_close(cstoreSkipNodes, NoLock); + table_close(columnarChunk, NoLock); - return skipList; + return chunkList; } /* - * InsertStripeMetadataRow adds a row to cstore_stripes. + * InsertStripeMetadataRow adds a row to columnar.stripe. */ static void InsertStripeMetadataRow(uint64 storageId, StripeMetadata *stripe) { - bool nulls[Natts_cstore_stripes] = { 0 }; - Datum values[Natts_cstore_stripes] = { + bool nulls[Natts_columnar_stripe] = { 0 }; + Datum values[Natts_columnar_stripe] = { UInt64GetDatum(storageId), Int64GetDatum(stripe->id), Int64GetDatum(stripe->fileOffset), @@ -585,10 +588,10 @@ InsertStripeMetadataRow(uint64 storageId, StripeMetadata *stripe) Int64GetDatum(stripe->rowCount) }; - Oid cstoreStripesOid = CStoreStripesRelationId(); - Relation cstoreStripes = table_open(cstoreStripesOid, RowExclusiveLock); + Oid columnarStripesOid = ColumnarStripeRelationId(); + Relation columnarStripes = table_open(columnarStripesOid, RowExclusiveLock); - ModifyState *modifyState = StartModifyRelation(cstoreStripes); + ModifyState *modifyState = StartModifyRelation(columnarStripes); InsertTupleAndEnforceConstraints(modifyState, values, nulls); @@ -596,7 +599,7 @@ InsertStripeMetadataRow(uint64 storageId, StripeMetadata *stripe) CommandCounterIncrement(); - table_close(cstoreStripes, NoLock); + table_close(columnarStripes, NoLock); } @@ -679,7 +682,7 @@ GetHighestUsedAddressAndId(uint64 storageId, /* * ReserveStripe reserves and stripe of given size for the given relation, - * and inserts it into cstore_stripes. It is guaranteed that concurrent + * and inserts it into columnar.stripe. It is guaranteed that concurrent * writes won't overwrite the returned stripe. */ StripeMetadata @@ -760,54 +763,54 @@ ReadDataFileStripeList(uint64 storageId, Snapshot snapshot) ScanKeyData scanKey[1]; HeapTuple heapTuple; - ScanKeyInit(&scanKey[0], Anum_cstore_stripes_storageid, + ScanKeyInit(&scanKey[0], Anum_columnar_stripe_storageid, BTEqualStrategyNumber, F_OIDEQ, Int32GetDatum(storageId)); - Oid cstoreStripesOid = CStoreStripesRelationId(); + Oid columnarStripesOid = ColumnarStripeRelationId(); - Relation cstoreStripes = table_open(cstoreStripesOid, AccessShareLock); - Relation index = index_open(CStoreStripesIndexRelationId(), AccessShareLock); - TupleDesc tupleDescriptor = RelationGetDescr(cstoreStripes); + Relation columnarStripes = table_open(columnarStripesOid, AccessShareLock); + Relation index = index_open(ColumnarStripeIndexRelationId(), AccessShareLock); + TupleDesc tupleDescriptor = RelationGetDescr(columnarStripes); - SysScanDesc scanDescriptor = systable_beginscan_ordered(cstoreStripes, index, + SysScanDesc scanDescriptor = systable_beginscan_ordered(columnarStripes, index, snapshot, 1, scanKey); while (HeapTupleIsValid(heapTuple = systable_getnext(scanDescriptor))) { - Datum datumArray[Natts_cstore_stripes]; - bool isNullArray[Natts_cstore_stripes]; + Datum datumArray[Natts_columnar_stripe]; + bool isNullArray[Natts_columnar_stripe]; heap_deform_tuple(heapTuple, tupleDescriptor, datumArray, isNullArray); StripeMetadata *stripeMetadata = palloc0(sizeof(StripeMetadata)); - stripeMetadata->id = DatumGetInt64(datumArray[Anum_cstore_stripes_stripe - 1]); + stripeMetadata->id = DatumGetInt64(datumArray[Anum_columnar_stripe_stripe - 1]); stripeMetadata->fileOffset = DatumGetInt64( - datumArray[Anum_cstore_stripes_file_offset - 1]); + datumArray[Anum_columnar_stripe_file_offset - 1]); stripeMetadata->dataLength = DatumGetInt64( - datumArray[Anum_cstore_stripes_data_length - 1]); + datumArray[Anum_columnar_stripe_data_length - 1]); stripeMetadata->columnCount = DatumGetInt32( - datumArray[Anum_cstore_stripes_column_count - 1]); + datumArray[Anum_columnar_stripe_column_count - 1]); stripeMetadata->chunkCount = DatumGetInt32( - datumArray[Anum_cstore_stripes_chunk_count - 1]); + datumArray[Anum_columnar_stripe_chunk_count - 1]); stripeMetadata->chunkRowCount = DatumGetInt32( - datumArray[Anum_cstore_stripes_chunk_row_count - 1]); + datumArray[Anum_columnar_stripe_chunk_row_count - 1]); stripeMetadata->rowCount = DatumGetInt64( - datumArray[Anum_cstore_stripes_row_count - 1]); + datumArray[Anum_columnar_stripe_row_count - 1]); stripeMetadataList = lappend(stripeMetadataList, stripeMetadata); } systable_endscan_ordered(scanDescriptor); index_close(index, NoLock); - table_close(cstoreStripes, NoLock); + table_close(columnarStripes, NoLock); return stripeMetadataList; } /* - * DeleteMetadataRows removes the rows with given relfilenode from cstore_stripes. + * DeleteMetadataRows removes the rows with given relfilenode from columnar.stripe. */ void DeleteMetadataRows(RelFileNode relfilenode) @@ -833,23 +836,23 @@ DeleteMetadataRows(RelFileNode relfilenode) return; } - ScanKeyInit(&scanKey[0], Anum_cstore_stripes_storageid, + ScanKeyInit(&scanKey[0], Anum_columnar_stripe_storageid, BTEqualStrategyNumber, F_INT8EQ, UInt64GetDatum(metapage->storageId)); - Oid cstoreStripesOid = CStoreStripesRelationId(); - Relation cstoreStripes = try_relation_open(cstoreStripesOid, AccessShareLock); - if (cstoreStripes == NULL) + Oid columnarStripesOid = ColumnarStripeRelationId(); + Relation columnarStripes = try_relation_open(columnarStripesOid, AccessShareLock); + if (columnarStripes == NULL) { /* extension has been dropped */ return; } - Relation index = index_open(CStoreStripesIndexRelationId(), AccessShareLock); + Relation index = index_open(ColumnarStripeIndexRelationId(), AccessShareLock); - SysScanDesc scanDescriptor = systable_beginscan_ordered(cstoreStripes, index, NULL, + SysScanDesc scanDescriptor = systable_beginscan_ordered(columnarStripes, index, NULL, 1, scanKey); - ModifyState *modifyState = StartModifyRelation(cstoreStripes); + ModifyState *modifyState = StartModifyRelation(columnarStripes); HeapTuple heapTuple = systable_getnext(scanDescriptor); while (HeapTupleIsValid(heapTuple)) @@ -862,7 +865,7 @@ DeleteMetadataRows(RelFileNode relfilenode) systable_endscan_ordered(scanDescriptor); index_close(index, NoLock); - table_close(cstoreStripes, NoLock); + table_close(columnarStripes, NoLock); } @@ -1046,24 +1049,24 @@ ByteaToDatum(bytea *bytes, Form_pg_attribute attrForm) /* - * CStoreStripesRelationId returns relation id of cstore_stripes. + * ColumnarStripeRelationId returns relation id of columnar.stripe. * TODO: should we cache this similar to citus? */ static Oid -CStoreStripesRelationId(void) +ColumnarStripeRelationId(void) { - return get_relname_relid("columnar_stripes", CStoreNamespaceId()); + return get_relname_relid("stripe", ColumnarNamespaceId()); } /* - * CStoreStripesIndexRelationId returns relation id of cstore_stripes_idx. + * ColumnarStripeIndexRelationId returns relation id of columnar.stripe_pkey. * TODO: should we cache this similar to citus? */ static Oid -CStoreStripesIndexRelationId(void) +ColumnarStripeIndexRelationId(void) { - return get_relname_relid("columnar_stripes_pkey", CStoreNamespaceId()); + return get_relname_relid("stripe_pkey", ColumnarNamespaceId()); } @@ -1073,7 +1076,7 @@ CStoreStripesIndexRelationId(void) static Oid ColumnarOptionsRelationId(void) { - return get_relname_relid("options", CStoreNamespaceId()); + return get_relname_relid("options", ColumnarNamespaceId()); } @@ -1083,38 +1086,38 @@ ColumnarOptionsRelationId(void) static Oid ColumnarOptionsIndexRegclass(void) { - return get_relname_relid("options_pkey", CStoreNamespaceId()); + return get_relname_relid("options_pkey", ColumnarNamespaceId()); } /* - * CStoreSkipNodesRelationId returns relation id of cstore_skipnodes. + * ColumnarChunkRelationId returns relation id of columnar.chunk. * TODO: should we cache this similar to citus? */ static Oid -CStoreSkipNodesRelationId(void) +ColumnarChunkRelationId(void) { - return get_relname_relid("columnar_skipnodes", CStoreNamespaceId()); + return get_relname_relid("chunk", ColumnarNamespaceId()); } /* - * CStoreSkipNodesIndexRelationId returns relation id of cstore_skipnodes_pkey. + * ColumnarChunkIndexRelationId returns relation id of columnar.chunk_pkey. * TODO: should we cache this similar to citus? */ static Oid -CStoreSkipNodesIndexRelationId(void) +ColumnarChunkIndexRelationId(void) { - return get_relname_relid("columnar_skipnodes_pkey", CStoreNamespaceId()); + return get_relname_relid("chunk_pkey", ColumnarNamespaceId()); } /* - * CStoreNamespaceId returns namespace id of the schema we store cstore + * ColumnarNamespaceId returns namespace id of the schema we store columnar * related tables. */ static Oid -CStoreNamespaceId(void) +ColumnarNamespaceId(void) { return get_namespace_oid("columnar", false); } @@ -1201,7 +1204,7 @@ GetNextStorageId(void) { Oid savedUserId = InvalidOid; int savedSecurityContext = 0; - Oid sequenceId = get_relname_relid("storageid_seq", CStoreNamespaceId()); + Oid sequenceId = get_relname_relid("storageid_seq", ColumnarNamespaceId()); Datum sequenceIdDatum = ObjectIdGetDatum(sequenceId); /* @@ -1236,7 +1239,7 @@ columnar_relation_storageid(PG_FUNCTION_ARGS) #if HAS_TABLEAM Oid relationId = PG_GETARG_OID(0); Relation relation = relation_open(relationId, AccessShareLock); - if (IsCStoreTableAmTable(relationId)) + if (IsColumnarTableAmTable(relationId)) { ColumnarMetapage *metadata = ReadMetapage(relation->rd_node, true); if (metadata != NULL) diff --git a/src/backend/columnar/cstore_reader.c b/src/backend/columnar/cstore_reader.c index ee2e49f8b..9906958f2 100644 --- a/src/backend/columnar/cstore_reader.c +++ b/src/backend/columnar/cstore_reader.c @@ -44,7 +44,8 @@ static StripeBuffers * LoadFilteredStripeBuffers(Relation relation, StripeMetadata *stripeMetadata, TupleDesc tupleDescriptor, List *projectedColumnList, - List *whereClauseList); + List *whereClauseList, + int64 *chunksFiltered); static void ReadStripeNextRow(StripeBuffers *stripeBuffers, List *projectedColumnList, uint64 chunkIndex, uint64 chunkRowIndex, ChunkData *chunkData, Datum *columnValues, @@ -54,7 +55,8 @@ static ColumnBuffers * LoadColumnBuffers(Relation relation, uint32 chunkCount, uint64 stripeOffset, Form_pg_attribute attributeForm); static bool * SelectedChunkMask(StripeSkipList *stripeSkipList, - List *projectedColumnList, List *whereClauseList); + List *projectedColumnList, List *whereClauseList, + int64 *chunksFiltered); static List * BuildRestrictInfoList(List *whereClauseList); static Node * BuildBaseConstraint(Var *variable); static OpExpr * MakeOpExpression(Var *variable, int16 strategyNumber); @@ -78,12 +80,12 @@ static Datum ColumnDefaultValue(TupleConstr *tupleConstraints, Form_pg_attribute attributeForm); /* - * CStoreBeginRead initializes a cstore read operation. This function returns a + * ColumnarBeginRead initializes a cstore read operation. This function returns a * read handle that's used during reading rows and finishing the read operation. */ TableReadState * -CStoreBeginRead(Relation relation, TupleDesc tupleDescriptor, - List *projectedColumnList, List *whereClauseList) +ColumnarBeginRead(Relation relation, TupleDesc tupleDescriptor, + List *projectedColumnList, List *whereClauseList) { List *stripeList = StripesForRelfilenode(relation->rd_node); @@ -104,6 +106,7 @@ CStoreBeginRead(Relation relation, TupleDesc tupleDescriptor, readState->stripeBuffers = NULL; readState->readStripeCount = 0; readState->stripeReadRowCount = 0; + readState->chunksFiltered = 0; readState->tupleDescriptor = tupleDescriptor; readState->stripeReadContext = stripeReadContext; readState->chunkData = NULL; @@ -114,12 +117,12 @@ CStoreBeginRead(Relation relation, TupleDesc tupleDescriptor, /* - * CStoreReadNextRow tries to read a row from the cstore file. On success, it sets + * ColumnarReadNextRow tries to read a row from the cstore file. On success, it sets * column values and nulls, and returns true. If there are no more rows to read, * the function returns false. */ bool -CStoreReadNextRow(TableReadState *readState, Datum *columnValues, bool *columnNulls) +ColumnarReadNextRow(TableReadState *readState, Datum *columnValues, bool *columnNulls) { StripeMetadata *stripeMetadata = readState->currentStripeMetadata; MemoryContext oldContext = NULL; @@ -153,7 +156,9 @@ CStoreReadNextRow(TableReadState *readState, Datum *columnValues, bool *columnNu readState-> projectedColumnList, readState-> - whereClauseList); + whereClauseList, + &readState-> + chunksFiltered); readState->readStripeCount++; readState->currentStripeMetadata = stripeMetadata; @@ -218,11 +223,11 @@ CStoreReadNextRow(TableReadState *readState, Datum *columnValues, bool *columnNu /* - * CStoreRescan clears the position where we were scanning so that the next read starts at + * ColumnarRescan clears the position where we were scanning so that the next read starts at * the beginning again */ void -CStoreRescan(TableReadState *readState) +ColumnarRescan(TableReadState *readState) { readState->stripeBuffers = NULL; readState->readStripeCount = 0; @@ -232,7 +237,7 @@ CStoreRescan(TableReadState *readState) /* Finishes a cstore read operation. */ void -CStoreEndRead(TableReadState *readState) +ColumnarEndRead(TableReadState *readState) { MemoryContextDelete(readState->stripeReadContext); list_free_deep(readState->stripeList); @@ -306,9 +311,9 @@ FreeChunkData(ChunkData *chunkData) } -/* CStoreTableRowCount returns the exact row count of a table using skiplists */ +/* ColumnarTableRowCount returns the exact row count of a table using skiplists */ uint64 -CStoreTableRowCount(Relation relation) +ColumnarTableRowCount(Relation relation) { ListCell *stripeMetadataCell = NULL; uint64 totalRowCount = 0; @@ -332,7 +337,7 @@ CStoreTableRowCount(Relation relation) static StripeBuffers * LoadFilteredStripeBuffers(Relation relation, StripeMetadata *stripeMetadata, TupleDesc tupleDescriptor, List *projectedColumnList, - List *whereClauseList) + List *whereClauseList, int64 *chunksFiltered) { uint32 columnIndex = 0; uint32 columnCount = tupleDescriptor->natts; @@ -345,7 +350,7 @@ LoadFilteredStripeBuffers(Relation relation, StripeMetadata *stripeMetadata, stripeMetadata->chunkCount); bool *selectedChunkMask = SelectedChunkMask(stripeSkipList, projectedColumnList, - whereClauseList); + whereClauseList, chunksFiltered); StripeSkipList *selectedChunkSkipList = SelectedChunkSkipList(stripeSkipList, projectedColumnMask, @@ -474,7 +479,7 @@ LoadColumnBuffers(Relation relation, ColumnChunkSkipNode *chunkSkipNodeArray, */ static bool * SelectedChunkMask(StripeSkipList *stripeSkipList, List *projectedColumnList, - List *whereClauseList) + List *whereClauseList, int64 *chunksFiltered) { ListCell *columnCell = NULL; uint32 chunkIndex = 0; @@ -527,6 +532,7 @@ SelectedChunkMask(StripeSkipList *stripeSkipList, List *projectedColumnList, if (predicateRefuted) { selectedChunkMask[chunkIndex] = false; + *chunksFiltered += 1; } } } diff --git a/src/backend/columnar/cstore_tableam.c b/src/backend/columnar/cstore_tableam.c index 293935e56..dca218ec1 100644 --- a/src/backend/columnar/cstore_tableam.c +++ b/src/backend/columnar/cstore_tableam.c @@ -69,10 +69,10 @@ #define VACUUM_TRUNCATE_LOCK_TIMEOUT 4500 /* ms */ /* - * CStoreScanDescData is the scan state passed between beginscan(), + * ColumnarScanDescData is the scan state passed between beginscan(), * getnextslot(), rescan(), and endscan() calls. */ -typedef struct CStoreScanDescData +typedef struct ColumnarScanDescData { TableScanDescData cs_base; TableReadState *cs_readState; @@ -90,26 +90,26 @@ typedef struct CStoreScanDescData * number so we can construct an item pointer based on that. */ int rowNumber; -} CStoreScanDescData; +} ColumnarScanDescData; -typedef struct CStoreScanDescData *CStoreScanDesc; +typedef struct ColumnarScanDescData *ColumnarScanDesc; static object_access_hook_type PrevObjectAccessHook = NULL; /* forward declaration for static functions */ -static void CStoreTableDropHook(Oid tgid); -static void CStoreTriggerCreateHook(Oid tgid); -static void CStoreTableAMObjectAccessHook(ObjectAccessType access, Oid classId, - Oid objectId, int subId, - void *arg); +static void ColumnarTableDropHook(Oid tgid); +static void ColumnarTriggerCreateHook(Oid tgid); +static void ColumnarTableAMObjectAccessHook(ObjectAccessType access, Oid classId, + Oid objectId, int subId, + void *arg); static bool ConditionalLockRelationWithTimeout(Relation rel, LOCKMODE lockMode, int timeout, int retryInterval); static void LogRelationStats(Relation rel, int elevel); -static void TruncateCStore(Relation rel, int elevel); +static void TruncateColumnar(Relation rel, int elevel); static HeapTuple ColumnarSlotCopyHeapTuple(TupleTableSlot *slot); static void ColumnarCheckLogicalReplication(Relation rel); -/* Custom tuple slot ops used for columnar. Initialized in cstore_tableam_init(). */ +/* Custom tuple slot ops used for columnar. Initialized in columnar_tableam_init(). */ TupleTableSlotOps TTSOpsColumnar; static List * @@ -142,17 +142,17 @@ RelationColumnList(Relation rel) static const TupleTableSlotOps * -cstore_slot_callbacks(Relation relation) +columnar_slot_callbacks(Relation relation) { return &TTSOpsColumnar; } static TableScanDesc -cstore_beginscan(Relation relation, Snapshot snapshot, - int nkeys, ScanKey key, - ParallelTableScanDesc parallel_scan, - uint32 flags) +columnar_beginscan(Relation relation, Snapshot snapshot, + int nkeys, ScanKey key, + ParallelTableScanDesc parallel_scan, + uint32 flags) { int natts = relation->rd_att->natts; Bitmapset *attr_needed = NULL; @@ -162,9 +162,9 @@ cstore_beginscan(Relation relation, Snapshot snapshot, /* the cstore access method does not use the flags, they are specific to heap */ flags = 0; - TableScanDesc scandesc = cstore_beginscan_extended(relation, snapshot, nkeys, key, - parallel_scan, - flags, attr_needed, NULL); + TableScanDesc scandesc = columnar_beginscan_extended(relation, snapshot, nkeys, key, + parallel_scan, + flags, attr_needed, NULL); pfree(attr_needed); @@ -173,10 +173,10 @@ cstore_beginscan(Relation relation, Snapshot snapshot, TableScanDesc -cstore_beginscan_extended(Relation relation, Snapshot snapshot, - int nkeys, ScanKey key, - ParallelTableScanDesc parallel_scan, - uint32 flags, Bitmapset *attr_needed, List *scanQual) +columnar_beginscan_extended(Relation relation, Snapshot snapshot, + int nkeys, ScanKey key, + ParallelTableScanDesc parallel_scan, + uint32 flags, Bitmapset *attr_needed, List *scanQual) { Oid relfilenode = relation->rd_node.relNode; @@ -193,7 +193,7 @@ cstore_beginscan_extended(Relation relation, Snapshot snapshot, MemoryContext oldContext = MemoryContextSwitchTo(scanContext); - CStoreScanDesc scan = palloc(sizeof(CStoreScanDescData)); + ColumnarScanDesc scan = palloc(sizeof(ColumnarScanDescData)); scan->cs_base.rs_rd = relation; scan->cs_base.rs_snapshot = snapshot; scan->cs_base.rs_nkeys = nkeys; @@ -228,12 +228,12 @@ cstore_beginscan_extended(Relation relation, Snapshot snapshot, /* - * init_cstore_read_state initializes a column store table read and returns the + * init_columnar_read_state initializes a column store table read and returns the * state. */ static TableReadState * -init_cstore_read_state(Relation relation, TupleDesc tupdesc, Bitmapset *attr_needed, - List *scanQual) +init_columnar_read_state(Relation relation, TupleDesc tupdesc, Bitmapset *attr_needed, + List *scanQual) { List *columnList = RelationColumnList(relation); ListCell *columnCell = NULL; @@ -250,41 +250,41 @@ init_cstore_read_state(Relation relation, TupleDesc tupdesc, Bitmapset *attr_nee } } - TableReadState *readState = CStoreBeginRead(relation, tupdesc, neededColumnList, - scanQual); + TableReadState *readState = ColumnarBeginRead(relation, tupdesc, neededColumnList, + scanQual); return readState; } static void -cstore_endscan(TableScanDesc sscan) +columnar_endscan(TableScanDesc sscan) { - CStoreScanDesc scan = (CStoreScanDesc) sscan; + ColumnarScanDesc scan = (ColumnarScanDesc) sscan; if (scan->cs_readState != NULL) { - CStoreEndRead(scan->cs_readState); + ColumnarEndRead(scan->cs_readState); scan->cs_readState = NULL; } } static void -cstore_rescan(TableScanDesc sscan, ScanKey key, bool set_params, - bool allow_strat, bool allow_sync, bool allow_pagemode) +columnar_rescan(TableScanDesc sscan, ScanKey key, bool set_params, + bool allow_strat, bool allow_sync, bool allow_pagemode) { - CStoreScanDesc scan = (CStoreScanDesc) sscan; + ColumnarScanDesc scan = (ColumnarScanDesc) sscan; if (scan->cs_readState != NULL) { - CStoreRescan(scan->cs_readState); + ColumnarRescan(scan->cs_readState); } } static bool -cstore_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot) +columnar_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot) { - CStoreScanDesc scan = (CStoreScanDesc) sscan; + ColumnarScanDesc scan = (ColumnarScanDesc) sscan; /* * if this is the first row, initialize read state. @@ -293,15 +293,15 @@ cstore_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot { MemoryContext oldContext = MemoryContextSwitchTo(scan->scanContext); scan->cs_readState = - init_cstore_read_state(scan->cs_base.rs_rd, slot->tts_tupleDescriptor, - scan->attr_needed, scan->scanQual); + init_columnar_read_state(scan->cs_base.rs_rd, slot->tts_tupleDescriptor, + scan->attr_needed, scan->scanQual); MemoryContextSwitchTo(oldContext); } ExecClearTuple(slot); - bool nextRowFound = CStoreReadNextRow(scan->cs_readState, slot->tts_values, - slot->tts_isnull); + bool nextRowFound = ColumnarReadNextRow(scan->cs_readState, slot->tts_values, + slot->tts_isnull); if (!nextRowFound) { @@ -328,28 +328,28 @@ cstore_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot static Size -cstore_parallelscan_estimate(Relation rel) +columnar_parallelscan_estimate(Relation rel) { elog(ERROR, "columnar_parallelscan_estimate not implemented"); } static Size -cstore_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan) +columnar_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan) { elog(ERROR, "columnar_parallelscan_initialize not implemented"); } static void -cstore_parallelscan_reinitialize(Relation rel, ParallelTableScanDesc pscan) +columnar_parallelscan_reinitialize(Relation rel, ParallelTableScanDesc pscan) { elog(ERROR, "columnar_parallelscan_reinitialize not implemented"); } static IndexFetchTableData * -cstore_index_fetch_begin(Relation rel) +columnar_index_fetch_begin(Relation rel) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("indexes not supported for columnar tables"))); @@ -357,7 +357,7 @@ cstore_index_fetch_begin(Relation rel) static void -cstore_index_fetch_reset(IndexFetchTableData *scan) +columnar_index_fetch_reset(IndexFetchTableData *scan) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("indexes not supported for columnar tables"))); @@ -365,7 +365,7 @@ cstore_index_fetch_reset(IndexFetchTableData *scan) static void -cstore_index_fetch_end(IndexFetchTableData *scan) +columnar_index_fetch_end(IndexFetchTableData *scan) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("indexes not supported for columnar tables"))); @@ -373,11 +373,11 @@ cstore_index_fetch_end(IndexFetchTableData *scan) static bool -cstore_index_fetch_tuple(struct IndexFetchTableData *scan, - ItemPointer tid, - Snapshot snapshot, - TupleTableSlot *slot, - bool *call_again, bool *all_dead) +columnar_index_fetch_tuple(struct IndexFetchTableData *scan, + ItemPointer tid, + Snapshot snapshot, + TupleTableSlot *slot, + bool *call_again, bool *all_dead) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("indexes not supported for columnar tables"))); @@ -385,58 +385,58 @@ cstore_index_fetch_tuple(struct IndexFetchTableData *scan, static bool -cstore_fetch_row_version(Relation relation, - ItemPointer tid, - Snapshot snapshot, - TupleTableSlot *slot) +columnar_fetch_row_version(Relation relation, + ItemPointer tid, + Snapshot snapshot, + TupleTableSlot *slot) { elog(ERROR, "columnar_fetch_row_version not implemented"); } static void -cstore_get_latest_tid(TableScanDesc sscan, - ItemPointer tid) +columnar_get_latest_tid(TableScanDesc sscan, + ItemPointer tid) { elog(ERROR, "columnar_get_latest_tid not implemented"); } static bool -cstore_tuple_tid_valid(TableScanDesc scan, ItemPointer tid) +columnar_tuple_tid_valid(TableScanDesc scan, ItemPointer tid) { elog(ERROR, "columnar_tuple_tid_valid not implemented"); } static bool -cstore_tuple_satisfies_snapshot(Relation rel, TupleTableSlot *slot, - Snapshot snapshot) +columnar_tuple_satisfies_snapshot(Relation rel, TupleTableSlot *slot, + Snapshot snapshot) { return true; } static TransactionId -cstore_compute_xid_horizon_for_tuples(Relation rel, - ItemPointerData *tids, - int nitems) +columnar_compute_xid_horizon_for_tuples(Relation rel, + ItemPointerData *tids, + int nitems) { elog(ERROR, "columnar_compute_xid_horizon_for_tuples not implemented"); } static void -cstore_tuple_insert(Relation relation, TupleTableSlot *slot, CommandId cid, - int options, BulkInsertState bistate) +columnar_tuple_insert(Relation relation, TupleTableSlot *slot, CommandId cid, + int options, BulkInsertState bistate) { /* - * cstore_init_write_state allocates the write state in a longer + * columnar_init_write_state allocates the write state in a longer * lasting context, so no need to worry about it. */ - TableWriteState *writeState = cstore_init_write_state(relation, - RelationGetDescr(relation), - GetCurrentSubTransactionId()); + TableWriteState *writeState = columnar_init_write_state(relation, + RelationGetDescr(relation), + GetCurrentSubTransactionId()); MemoryContext oldContext = MemoryContextSwitchTo(writeState->perTupleContext); @@ -454,7 +454,7 @@ cstore_tuple_insert(Relation relation, TupleTableSlot *slot, CommandId cid, slot_getallattrs(slot); - CStoreWriteRow(writeState, slot->tts_values, slot->tts_isnull); + ColumnarWriteRow(writeState, slot->tts_values, slot->tts_isnull); MemoryContextSwitchTo(oldContext); MemoryContextReset(writeState->perTupleContext); @@ -462,29 +462,29 @@ cstore_tuple_insert(Relation relation, TupleTableSlot *slot, CommandId cid, static void -cstore_tuple_insert_speculative(Relation relation, TupleTableSlot *slot, - CommandId cid, int options, - BulkInsertState bistate, uint32 specToken) +columnar_tuple_insert_speculative(Relation relation, TupleTableSlot *slot, + CommandId cid, int options, + BulkInsertState bistate, uint32 specToken) { elog(ERROR, "columnar_tuple_insert_speculative not implemented"); } static void -cstore_tuple_complete_speculative(Relation relation, TupleTableSlot *slot, - uint32 specToken, bool succeeded) +columnar_tuple_complete_speculative(Relation relation, TupleTableSlot *slot, + uint32 specToken, bool succeeded) { elog(ERROR, "columnar_tuple_complete_speculative not implemented"); } static void -cstore_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples, - CommandId cid, int options, BulkInsertState bistate) +columnar_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples, + CommandId cid, int options, BulkInsertState bistate) { - TableWriteState *writeState = cstore_init_write_state(relation, - RelationGetDescr(relation), - GetCurrentSubTransactionId()); + TableWriteState *writeState = columnar_init_write_state(relation, + RelationGetDescr(relation), + GetCurrentSubTransactionId()); ColumnarCheckLogicalReplication(relation); for (int i = 0; i < ntuples; i++) @@ -504,7 +504,7 @@ cstore_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples, slot_getallattrs(tupleSlot); - CStoreWriteRow(writeState, tupleSlot->tts_values, tupleSlot->tts_isnull); + ColumnarWriteRow(writeState, tupleSlot->tts_values, tupleSlot->tts_isnull); MemoryContextSwitchTo(oldContext); } @@ -513,36 +513,36 @@ cstore_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples, static TM_Result -cstore_tuple_delete(Relation relation, ItemPointer tid, CommandId cid, - Snapshot snapshot, Snapshot crosscheck, bool wait, - TM_FailureData *tmfd, bool changingPart) +columnar_tuple_delete(Relation relation, ItemPointer tid, CommandId cid, + Snapshot snapshot, Snapshot crosscheck, bool wait, + TM_FailureData *tmfd, bool changingPart) { elog(ERROR, "columnar_tuple_delete not implemented"); } static TM_Result -cstore_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot, - CommandId cid, Snapshot snapshot, Snapshot crosscheck, - bool wait, TM_FailureData *tmfd, - LockTupleMode *lockmode, bool *update_indexes) +columnar_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot, + CommandId cid, Snapshot snapshot, Snapshot crosscheck, + bool wait, TM_FailureData *tmfd, + LockTupleMode *lockmode, bool *update_indexes) { elog(ERROR, "columnar_tuple_update not implemented"); } static TM_Result -cstore_tuple_lock(Relation relation, ItemPointer tid, Snapshot snapshot, - TupleTableSlot *slot, CommandId cid, LockTupleMode mode, - LockWaitPolicy wait_policy, uint8 flags, - TM_FailureData *tmfd) +columnar_tuple_lock(Relation relation, ItemPointer tid, Snapshot snapshot, + TupleTableSlot *slot, CommandId cid, LockTupleMode mode, + LockWaitPolicy wait_policy, uint8 flags, + TM_FailureData *tmfd) { elog(ERROR, "columnar_tuple_lock not implemented"); } static void -cstore_finish_bulk_insert(Relation relation, int options) +columnar_finish_bulk_insert(Relation relation, int options) { /* * Nothing to do here. We keep write states live until transaction end. @@ -551,11 +551,11 @@ cstore_finish_bulk_insert(Relation relation, int options) static void -cstore_relation_set_new_filenode(Relation rel, - const RelFileNode *newrnode, - char persistence, - TransactionId *freezeXid, - MultiXactId *minmulti) +columnar_relation_set_new_filenode(Relation rel, + const RelFileNode *newrnode, + char persistence, + TransactionId *freezeXid, + MultiXactId *minmulti) { if (persistence != RELPERSISTENCE_PERMANENT) { @@ -584,7 +584,7 @@ cstore_relation_set_new_filenode(Relation rel, static void -cstore_relation_nontransactional_truncate(Relation rel) +columnar_relation_nontransactional_truncate(Relation rel) { RelFileNode relfilenode = rel->rd_node; @@ -607,28 +607,28 @@ cstore_relation_nontransactional_truncate(Relation rel) static void -cstore_relation_copy_data(Relation rel, const RelFileNode *newrnode) +columnar_relation_copy_data(Relation rel, const RelFileNode *newrnode) { elog(ERROR, "columnar_relation_copy_data not implemented"); } /* - * cstore_relation_copy_for_cluster is called on VACUUM FULL, at which + * columnar_relation_copy_for_cluster is called on VACUUM FULL, at which * we should copy data from OldHeap to NewHeap. * * In general TableAM case this can also be called for the CLUSTER command * which is not applicable for cstore since it doesn't support indexes. */ static void -cstore_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap, - Relation OldIndex, bool use_sort, - TransactionId OldestXmin, - TransactionId *xid_cutoff, - MultiXactId *multi_cutoff, - double *num_tuples, - double *tups_vacuumed, - double *tups_recently_dead) +columnar_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap, + Relation OldIndex, bool use_sort, + TransactionId OldestXmin, + TransactionId *xid_cutoff, + MultiXactId *multi_cutoff, + double *num_tuples, + double *tups_vacuumed, + double *tups_recently_dead) { TupleDesc sourceDesc = RelationGetDescr(OldHeap); TupleDesc targetDesc = RelationGetDescr(NewHeap); @@ -650,37 +650,37 @@ cstore_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap, ColumnarOptions cstoreOptions = { 0 }; ReadColumnarOptions(OldHeap->rd_id, &cstoreOptions); - TableWriteState *writeState = CStoreBeginWrite(NewHeap->rd_node, - cstoreOptions, - targetDesc); + TableWriteState *writeState = ColumnarBeginWrite(NewHeap->rd_node, + cstoreOptions, + targetDesc); - TableReadState *readState = CStoreBeginRead(OldHeap, sourceDesc, - RelationColumnList(OldHeap), NULL); + TableReadState *readState = ColumnarBeginRead(OldHeap, sourceDesc, + RelationColumnList(OldHeap), NULL); Datum *values = palloc0(sourceDesc->natts * sizeof(Datum)); bool *nulls = palloc0(sourceDesc->natts * sizeof(bool)); *num_tuples = 0; - while (CStoreReadNextRow(readState, values, nulls)) + while (ColumnarReadNextRow(readState, values, nulls)) { - CStoreWriteRow(writeState, values, nulls); + ColumnarWriteRow(writeState, values, nulls); (*num_tuples)++; } *tups_vacuumed = 0; - CStoreEndWrite(writeState); - CStoreEndRead(readState); + ColumnarEndWrite(writeState); + ColumnarEndRead(readState); } /* - * cstore_vacuum_rel implements VACUUM without FULL option. + * columnar_vacuum_rel implements VACUUM without FULL option. */ static void -cstore_vacuum_rel(Relation rel, VacuumParams *params, - BufferAccessStrategy bstrategy) +columnar_vacuum_rel(Relation rel, VacuumParams *params, + BufferAccessStrategy bstrategy) { int elevel = (params->options & VACOPT_VERBOSE) ? INFO : DEBUG2; @@ -695,7 +695,7 @@ cstore_vacuum_rel(Relation rel, VacuumParams *params, */ if (params->truncate == VACOPT_TERNARY_ENABLED) { - TruncateCStore(rel, elevel); + TruncateColumnar(rel, elevel); } } @@ -813,14 +813,14 @@ LogRelationStats(Relation rel, int elevel) /* - * TruncateCStore truncates the unused space at the end of main fork for + * TruncateColumnar truncates the unused space at the end of main fork for * a cstore table. This unused space can be created by aborted transactions. * * This implementation is based on heap_vacuum_rel in vacuumlazy.c with some * changes so it suits columnar store relations. */ static void -TruncateCStore(Relation rel, int elevel) +TruncateColumnar(Relation rel, int elevel) { PGRUsage ru0; @@ -939,23 +939,23 @@ ConditionalLockRelationWithTimeout(Relation rel, LOCKMODE lockMode, int timeout, static bool -cstore_scan_analyze_next_block(TableScanDesc scan, BlockNumber blockno, - BufferAccessStrategy bstrategy) +columnar_scan_analyze_next_block(TableScanDesc scan, BlockNumber blockno, + BufferAccessStrategy bstrategy) { /* * Our access method is not pages based, i.e. tuples are not confined * to pages boundaries. So not much to do here. We return true anyway * so acquire_sample_rows() in analyze.c would call our - * cstore_scan_analyze_next_tuple() callback. + * columnar_scan_analyze_next_tuple() callback. */ return true; } static bool -cstore_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin, - double *liverows, double *deadrows, - TupleTableSlot *slot) +columnar_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin, + double *liverows, double *deadrows, + TupleTableSlot *slot) { /* * Currently we don't do anything smart to reduce number of rows returned @@ -964,11 +964,11 @@ cstore_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin, * tuples from those pages. * * We could do something like that here by choosing sample stripes or chunks, - * but getting that correct might need quite some work. Since cstore_fdw's + * but getting that correct might need quite some work. Since columnar_fdw's * ANALYZE scanned all rows, as a starter we do the same here and scan all * rows. */ - if (cstore_getnextslot(scan, ForwardScanDirection, slot)) + if (columnar_getnextslot(scan, ForwardScanDirection, slot)) { (*liverows)++; return true; @@ -979,17 +979,17 @@ cstore_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin, static double -cstore_index_build_range_scan(Relation heapRelation, - Relation indexRelation, - IndexInfo *indexInfo, - bool allow_sync, - bool anyvisible, - bool progress, - BlockNumber start_blockno, - BlockNumber numblocks, - IndexBuildCallback callback, - void *callback_state, - TableScanDesc scan) +columnar_index_build_range_scan(Relation heapRelation, + Relation indexRelation, + IndexInfo *indexInfo, + bool allow_sync, + bool anyvisible, + bool progress, + BlockNumber start_blockno, + BlockNumber numblocks, + IndexBuildCallback callback, + void *callback_state, + TableScanDesc scan) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("indexes not supported for columnar tables"))); @@ -997,11 +997,11 @@ cstore_index_build_range_scan(Relation heapRelation, static void -cstore_index_validate_scan(Relation heapRelation, - Relation indexRelation, - IndexInfo *indexInfo, - Snapshot snapshot, - ValidateIndexState *state) +columnar_index_validate_scan(Relation heapRelation, + Relation indexRelation, + IndexInfo *indexInfo, + Snapshot snapshot, + ValidateIndexState *state) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("indexes not supported for columnar tables"))); @@ -1009,7 +1009,7 @@ cstore_index_validate_scan(Relation heapRelation, static uint64 -cstore_relation_size(Relation rel, ForkNumber forkNumber) +columnar_relation_size(Relation rel, ForkNumber forkNumber) { uint64 nblocks = 0; @@ -1034,20 +1034,20 @@ cstore_relation_size(Relation rel, ForkNumber forkNumber) static bool -cstore_relation_needs_toast_table(Relation rel) +columnar_relation_needs_toast_table(Relation rel) { return false; } static void -cstore_estimate_rel_size(Relation rel, int32 *attr_widths, - BlockNumber *pages, double *tuples, - double *allvisfrac) +columnar_estimate_rel_size(Relation rel, int32 *attr_widths, + BlockNumber *pages, double *tuples, + double *allvisfrac) { RelationOpenSmgr(rel); *pages = smgrnblocks(rel->rd_smgr, MAIN_FORKNUM); - *tuples = CStoreTableRowCount(rel); + *tuples = ColumnarTableRowCount(rel); /* * Append-only, so everything is visible except in-progress or rolled-back @@ -1060,22 +1060,22 @@ cstore_estimate_rel_size(Relation rel, int32 *attr_widths, static bool -cstore_scan_sample_next_block(TableScanDesc scan, SampleScanState *scanstate) +columnar_scan_sample_next_block(TableScanDesc scan, SampleScanState *scanstate) { elog(ERROR, "columnar_scan_sample_next_block not implemented"); } static bool -cstore_scan_sample_next_tuple(TableScanDesc scan, SampleScanState *scanstate, - TupleTableSlot *slot) +columnar_scan_sample_next_tuple(TableScanDesc scan, SampleScanState *scanstate, + TupleTableSlot *slot) { elog(ERROR, "columnar_scan_sample_next_tuple not implemented"); } static void -CStoreXactCallback(XactEvent event, void *arg) +ColumnarXactCallback(XactEvent event, void *arg) { switch (event) { @@ -1106,8 +1106,8 @@ CStoreXactCallback(XactEvent event, void *arg) static void -CStoreSubXactCallback(SubXactEvent event, SubTransactionId mySubid, - SubTransactionId parentSubid, void *arg) +ColumnarSubXactCallback(SubXactEvent event, SubTransactionId mySubid, + SubTransactionId parentSubid, void *arg) { switch (event) { @@ -1134,15 +1134,15 @@ CStoreSubXactCallback(SubXactEvent event, SubTransactionId mySubid, void -cstore_tableam_init() +columnar_tableam_init() { - RegisterXactCallback(CStoreXactCallback, NULL); - RegisterSubXactCallback(CStoreSubXactCallback, NULL); + RegisterXactCallback(ColumnarXactCallback, NULL); + RegisterSubXactCallback(ColumnarSubXactCallback, NULL); PrevObjectAccessHook = object_access_hook; - object_access_hook = CStoreTableAMObjectAccessHook; + object_access_hook = ColumnarTableAMObjectAccessHook; - cstore_customscan_init(); + columnar_customscan_init(); TTSOpsColumnar = TTSOpsVirtual; TTSOpsColumnar.copy_heap_tuple = ColumnarSlotCopyHeapTuple; @@ -1150,12 +1150,32 @@ cstore_tableam_init() void -cstore_tableam_finish() +columnar_tableam_finish() { object_access_hook = PrevObjectAccessHook; } +/* + * Get the number of chunks filtered out during the given scan. + */ +int64 +ColumnarGetChunksFiltered(TableScanDesc scanDesc) +{ + ColumnarScanDesc cstoreScanDesc = (ColumnarScanDesc) scanDesc; + TableReadState *readState = cstoreScanDesc->cs_readState; + + if (readState != NULL) + { + return readState->chunksFiltered; + } + else + { + return 0; + } +} + + /* * Implementation of TupleTableSlotOps.copy_heap_tuple for TTSOpsColumnar. */ @@ -1173,7 +1193,7 @@ ColumnarSlotCopyHeapTuple(TupleTableSlot *slot) * requires it. See the qsort in acquire_sample_rows() and * also compare_rows in backend/commands/analyze.c. * - * slot->tts_tid is filled in cstore_getnextslot. + * slot->tts_tid is filled in columnar_getnextslot. */ tuple->t_self = slot->tts_tid; @@ -1182,12 +1202,12 @@ ColumnarSlotCopyHeapTuple(TupleTableSlot *slot) /* - * CStoreTableDropHook + * ColumnarTableDropHook * * Clean-up resources for columnar tables. */ static void -CStoreTableDropHook(Oid relid) +ColumnarTableDropHook(Oid relid) { /* * Lock relation to prevent it from being dropped and to avoid @@ -1195,7 +1215,7 @@ CStoreTableDropHook(Oid relid) */ LockRelationOid(relid, AccessShareLock); - if (IsCStoreTableAmTable(relid)) + if (IsColumnarTableAmTable(relid)) { /* * Drop metadata. No need to drop storage here since for @@ -1219,7 +1239,7 @@ CStoreTableDropHook(Oid relid) * Reject AFTER ... FOR EACH ROW triggers on columnar tables. */ static void -CStoreTriggerCreateHook(Oid tgid) +ColumnarTriggerCreateHook(Oid tgid) { /* * Fetch the pg_trigger tuple by the Oid of the trigger @@ -1252,7 +1272,7 @@ CStoreTriggerCreateHook(Oid tgid) table_close(tgrel, AccessShareLock); if (TRIGGER_FOR_ROW(tgtype) && TRIGGER_FOR_AFTER(tgtype) && - IsCStoreTableAmTable(tgrelid)) + IsColumnarTableAmTable(tgrelid)) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg( @@ -1266,8 +1286,8 @@ CStoreTriggerCreateHook(Oid tgid) * Capture create/drop events and dispatch to the proper action. */ static void -CStoreTableAMObjectAccessHook(ObjectAccessType access, Oid classId, Oid objectId, - int subId, void *arg) +ColumnarTableAMObjectAccessHook(ObjectAccessType access, Oid classId, Oid objectId, + int subId, void *arg) { if (PrevObjectAccessHook) { @@ -1277,21 +1297,21 @@ CStoreTableAMObjectAccessHook(ObjectAccessType access, Oid classId, Oid objectId /* dispatch to the proper action */ if (access == OAT_DROP && classId == RelationRelationId && !OidIsValid(subId)) { - CStoreTableDropHook(objectId); + ColumnarTableDropHook(objectId); } else if (access == OAT_POST_CREATE && classId == TriggerRelationId) { - CStoreTriggerCreateHook(objectId); + ColumnarTriggerCreateHook(objectId); } } /* - * IsCStoreTableAmTable returns true if relation has cstore_tableam + * IsColumnarTableAmTable returns true if relation has columnar_tableam * access method. This can be called before extension creation. */ bool -IsCStoreTableAmTable(Oid relationId) +IsColumnarTableAmTable(Oid relationId) { if (!OidIsValid(relationId)) { @@ -1310,66 +1330,66 @@ IsCStoreTableAmTable(Oid relationId) } -static const TableAmRoutine cstore_am_methods = { +static const TableAmRoutine columnar_am_methods = { .type = T_TableAmRoutine, - .slot_callbacks = cstore_slot_callbacks, + .slot_callbacks = columnar_slot_callbacks, - .scan_begin = cstore_beginscan, - .scan_end = cstore_endscan, - .scan_rescan = cstore_rescan, - .scan_getnextslot = cstore_getnextslot, + .scan_begin = columnar_beginscan, + .scan_end = columnar_endscan, + .scan_rescan = columnar_rescan, + .scan_getnextslot = columnar_getnextslot, - .parallelscan_estimate = cstore_parallelscan_estimate, - .parallelscan_initialize = cstore_parallelscan_initialize, - .parallelscan_reinitialize = cstore_parallelscan_reinitialize, + .parallelscan_estimate = columnar_parallelscan_estimate, + .parallelscan_initialize = columnar_parallelscan_initialize, + .parallelscan_reinitialize = columnar_parallelscan_reinitialize, - .index_fetch_begin = cstore_index_fetch_begin, - .index_fetch_reset = cstore_index_fetch_reset, - .index_fetch_end = cstore_index_fetch_end, - .index_fetch_tuple = cstore_index_fetch_tuple, + .index_fetch_begin = columnar_index_fetch_begin, + .index_fetch_reset = columnar_index_fetch_reset, + .index_fetch_end = columnar_index_fetch_end, + .index_fetch_tuple = columnar_index_fetch_tuple, - .tuple_fetch_row_version = cstore_fetch_row_version, - .tuple_get_latest_tid = cstore_get_latest_tid, - .tuple_tid_valid = cstore_tuple_tid_valid, - .tuple_satisfies_snapshot = cstore_tuple_satisfies_snapshot, - .compute_xid_horizon_for_tuples = cstore_compute_xid_horizon_for_tuples, + .tuple_fetch_row_version = columnar_fetch_row_version, + .tuple_get_latest_tid = columnar_get_latest_tid, + .tuple_tid_valid = columnar_tuple_tid_valid, + .tuple_satisfies_snapshot = columnar_tuple_satisfies_snapshot, + .compute_xid_horizon_for_tuples = columnar_compute_xid_horizon_for_tuples, - .tuple_insert = cstore_tuple_insert, - .tuple_insert_speculative = cstore_tuple_insert_speculative, - .tuple_complete_speculative = cstore_tuple_complete_speculative, - .multi_insert = cstore_multi_insert, - .tuple_delete = cstore_tuple_delete, - .tuple_update = cstore_tuple_update, - .tuple_lock = cstore_tuple_lock, - .finish_bulk_insert = cstore_finish_bulk_insert, + .tuple_insert = columnar_tuple_insert, + .tuple_insert_speculative = columnar_tuple_insert_speculative, + .tuple_complete_speculative = columnar_tuple_complete_speculative, + .multi_insert = columnar_multi_insert, + .tuple_delete = columnar_tuple_delete, + .tuple_update = columnar_tuple_update, + .tuple_lock = columnar_tuple_lock, + .finish_bulk_insert = columnar_finish_bulk_insert, - .relation_set_new_filenode = cstore_relation_set_new_filenode, - .relation_nontransactional_truncate = cstore_relation_nontransactional_truncate, - .relation_copy_data = cstore_relation_copy_data, - .relation_copy_for_cluster = cstore_relation_copy_for_cluster, - .relation_vacuum = cstore_vacuum_rel, - .scan_analyze_next_block = cstore_scan_analyze_next_block, - .scan_analyze_next_tuple = cstore_scan_analyze_next_tuple, - .index_build_range_scan = cstore_index_build_range_scan, - .index_validate_scan = cstore_index_validate_scan, + .relation_set_new_filenode = columnar_relation_set_new_filenode, + .relation_nontransactional_truncate = columnar_relation_nontransactional_truncate, + .relation_copy_data = columnar_relation_copy_data, + .relation_copy_for_cluster = columnar_relation_copy_for_cluster, + .relation_vacuum = columnar_vacuum_rel, + .scan_analyze_next_block = columnar_scan_analyze_next_block, + .scan_analyze_next_tuple = columnar_scan_analyze_next_tuple, + .index_build_range_scan = columnar_index_build_range_scan, + .index_validate_scan = columnar_index_validate_scan, - .relation_size = cstore_relation_size, - .relation_needs_toast_table = cstore_relation_needs_toast_table, + .relation_size = columnar_relation_size, + .relation_needs_toast_table = columnar_relation_needs_toast_table, - .relation_estimate_size = cstore_estimate_rel_size, + .relation_estimate_size = columnar_estimate_rel_size, .scan_bitmap_next_block = NULL, .scan_bitmap_next_tuple = NULL, - .scan_sample_next_block = cstore_scan_sample_next_block, - .scan_sample_next_tuple = cstore_scan_sample_next_tuple + .scan_sample_next_block = columnar_scan_sample_next_block, + .scan_sample_next_tuple = columnar_scan_sample_next_tuple }; const TableAmRoutine * GetColumnarTableAmRoutine(void) { - return &cstore_am_methods; + return &columnar_am_methods; } @@ -1377,7 +1397,7 @@ PG_FUNCTION_INFO_V1(columnar_handler); Datum columnar_handler(PG_FUNCTION_ARGS) { - PG_RETURN_POINTER(&cstore_am_methods); + PG_RETURN_POINTER(&columnar_am_methods); } @@ -1553,7 +1573,7 @@ alter_columnar_table_set(PG_FUNCTION_ARGS) Oid relationId = PG_GETARG_OID(0); Relation rel = table_open(relationId, AccessExclusiveLock); /* ALTER TABLE LOCK */ - if (!IsCStoreTableAmTable(relationId)) + if (!IsColumnarTableAmTable(relationId)) { ereport(ERROR, (errmsg("table %s is not a columnar table", quote_identifier(RelationGetRelationName(rel))))); @@ -1660,7 +1680,7 @@ alter_columnar_table_reset(PG_FUNCTION_ARGS) Oid relationId = PG_GETARG_OID(0); Relation rel = table_open(relationId, AccessExclusiveLock); /* ALTER TABLE LOCK */ - if (!IsCStoreTableAmTable(relationId)) + if (!IsColumnarTableAmTable(relationId)) { ereport(ERROR, (errmsg("table %s is not a columnar table", quote_identifier(RelationGetRelationName(rel))))); @@ -1675,7 +1695,7 @@ alter_columnar_table_reset(PG_FUNCTION_ARGS) /* chunk_row_count => true */ if (!PG_ARGISNULL(1) && PG_GETARG_BOOL(1)) { - options.chunkRowCount = cstore_chunk_row_count; + options.chunkRowCount = columnar_chunk_row_count; ereport(DEBUG1, (errmsg("resetting chunk row count to %d", options.chunkRowCount))); } @@ -1683,7 +1703,7 @@ alter_columnar_table_reset(PG_FUNCTION_ARGS) /* stripe_row_count => true */ if (!PG_ARGISNULL(2) && PG_GETARG_BOOL(2)) { - options.stripeRowCount = cstore_stripe_row_count; + options.stripeRowCount = columnar_stripe_row_count; ereport(DEBUG1, (errmsg("resetting stripe row count to " UINT64_FORMAT, options.stripeRowCount))); @@ -1692,7 +1712,7 @@ alter_columnar_table_reset(PG_FUNCTION_ARGS) /* compression => true */ if (!PG_ARGISNULL(3) && PG_GETARG_BOOL(3)) { - options.compressionType = cstore_compression; + options.compressionType = columnar_compression; ereport(DEBUG1, (errmsg("resetting compression to %s", CompressionTypeStr(options.compressionType)))); } diff --git a/src/backend/columnar/cstore_writer.c b/src/backend/columnar/cstore_writer.c index 548b3cfc5..b203bd2d5 100644 --- a/src/backend/columnar/cstore_writer.c +++ b/src/backend/columnar/cstore_writer.c @@ -53,16 +53,16 @@ static Datum DatumCopy(Datum datum, bool datumTypeByValue, int datumTypeLength); static StringInfo CopyStringInfo(StringInfo sourceString); /* - * CStoreBeginWrite initializes a cstore data load operation and returns a table + * ColumnarBeginWrite initializes a cstore data load operation and returns a table * handle. This handle should be used for adding the row values and finishing the * data load operation. If the cstore footer file already exists, we read the * footer and then seek to right after the last stripe where the new stripes * will be added. */ TableWriteState * -CStoreBeginWrite(RelFileNode relfilenode, - ColumnarOptions options, - TupleDesc tupleDescriptor) +ColumnarBeginWrite(RelFileNode relfilenode, + ColumnarOptions options, + TupleDesc tupleDescriptor) { /* get comparison function pointers for each of the columns */ uint32 columnCount = tupleDescriptor->natts; @@ -110,7 +110,7 @@ CStoreBeginWrite(RelFileNode relfilenode, writeState->chunkData = chunkData; writeState->compressionBuffer = NULL; writeState->perTupleContext = AllocSetContextCreate(CurrentMemoryContext, - "CStore per tuple context", + "Columnar per tuple context", ALLOCSET_DEFAULT_SIZES); return writeState; @@ -118,7 +118,7 @@ CStoreBeginWrite(RelFileNode relfilenode, /* - * CStoreWriteRow adds a row to the cstore file. If the stripe is not initialized, + * ColumnarWriteRow adds a row to the cstore file. If the stripe is not initialized, * we create structures to hold stripe data and skip list. Then, we serialize and * append data to serialized value buffer for each of the columns and update * corresponding skip nodes. Then, whole chunk data is compressed at every @@ -126,7 +126,7 @@ CStoreBeginWrite(RelFileNode relfilenode, * the stripe, and add its metadata to the table footer. */ void -CStoreWriteRow(TableWriteState *writeState, Datum *columnValues, bool *columnNulls) +ColumnarWriteRow(TableWriteState *writeState, Datum *columnValues, bool *columnNulls) { uint32 columnIndex = 0; StripeBuffers *stripeBuffers = writeState->stripeBuffers; @@ -206,7 +206,7 @@ CStoreWriteRow(TableWriteState *writeState, Datum *columnValues, bool *columnNul stripeBuffers->rowCount++; if (stripeBuffers->rowCount >= options->stripeRowCount) { - CStoreFlushPendingWrites(writeState); + ColumnarFlushPendingWrites(writeState); } MemoryContextSwitchTo(oldContext); @@ -214,15 +214,15 @@ CStoreWriteRow(TableWriteState *writeState, Datum *columnValues, bool *columnNul /* - * CStoreEndWrite finishes a cstore data load operation. If we have an unflushed + * ColumnarEndWrite finishes a cstore data load operation. If we have an unflushed * stripe, we flush it. Then, we sync and close the cstore data file. Last, we * flush the footer to a temporary file, and atomically rename this temporary * file to the original footer file. */ void -CStoreEndWrite(TableWriteState *writeState) +ColumnarEndWrite(TableWriteState *writeState) { - CStoreFlushPendingWrites(writeState); + ColumnarFlushPendingWrites(writeState); MemoryContextDelete(writeState->stripeWriteContext); pfree(writeState->comparisonFunctionArray); @@ -232,7 +232,7 @@ CStoreEndWrite(TableWriteState *writeState) void -CStoreFlushPendingWrites(TableWriteState *writeState) +ColumnarFlushPendingWrites(TableWriteState *writeState) { StripeBuffers *stripeBuffers = writeState->stripeBuffers; if (stripeBuffers != NULL) diff --git a/src/backend/columnar/mod.c b/src/backend/columnar/mod.c index a98c81021..10d8a5507 100644 --- a/src/backend/columnar/mod.c +++ b/src/backend/columnar/mod.c @@ -27,9 +27,9 @@ void columnar_init(void) { - cstore_init(); + columnar_init_gucs(); #ifdef HAS_TABLEAM - cstore_tableam_init(); + columnar_tableam_init(); #endif } @@ -38,6 +38,6 @@ void columnar_fini(void) { #if HAS_TABLEAM - cstore_tableam_finish(); + columnar_tableam_finish(); #endif } diff --git a/src/backend/columnar/sql/columnar--9.5-1--10.0-1.sql b/src/backend/columnar/sql/columnar--9.5-1--10.0-1.sql index c8c6feded..d28f24e43 100644 --- a/src/backend/columnar/sql/columnar--9.5-1--10.0-1.sql +++ b/src/backend/columnar/sql/columnar--9.5-1--10.0-1.sql @@ -15,25 +15,25 @@ CREATE TABLE options ( COMMENT ON TABLE options IS 'columnar table specific options, maintained by alter_columnar_table_set'; -CREATE TABLE columnar_stripes ( +CREATE TABLE stripe ( storageid bigint NOT NULL, - stripe bigint NOT NULL, + stripeid bigint NOT NULL, file_offset bigint NOT NULL, data_length bigint NOT NULL, column_count int NOT NULL, chunk_count int NOT NULL, chunk_row_count int NOT NULL, row_count bigint NOT NULL, - PRIMARY KEY (storageid, stripe) + PRIMARY KEY (storageid, stripeid) ) WITH (user_catalog_table = true); -COMMENT ON TABLE columnar_stripes IS 'Columnar per stripe metadata'; +COMMENT ON TABLE stripe IS 'Columnar per stripe metadata'; -CREATE TABLE columnar_skipnodes ( +CREATE TABLE chunk ( storageid bigint NOT NULL, - stripe bigint NOT NULL, - attr int NOT NULL, - chunk int NOT NULL, + stripeid bigint NOT NULL, + attnum int NOT NULL, + chunkid int NOT NULL, row_count bigint NOT NULL, minimum_value bytea, maximum_value bytea, @@ -44,11 +44,11 @@ CREATE TABLE columnar_skipnodes ( value_compression_type int NOT NULL, value_compression_level int NOT NULL, value_decompressed_length bigint NOT NULL, - PRIMARY KEY (storageid, stripe, attr, chunk), - FOREIGN KEY (storageid, stripe) REFERENCES columnar_stripes(storageid, stripe) ON DELETE CASCADE + PRIMARY KEY (storageid, stripeid, attnum, chunkid), + FOREIGN KEY (storageid, stripeid) REFERENCES stripe(storageid, stripeid) ON DELETE CASCADE ) WITH (user_catalog_table = true); -COMMENT ON TABLE columnar_skipnodes IS 'Columnar per chunk metadata'; +COMMENT ON TABLE chunk IS 'Columnar per chunk metadata'; DO $proc$ BEGIN diff --git a/src/backend/columnar/sql/downgrades/columnar--10.0-1--9.5-1.sql b/src/backend/columnar/sql/downgrades/columnar--10.0-1--9.5-1.sql index 610e72178..c171d9182 100644 --- a/src/backend/columnar/sql/downgrades/columnar--10.0-1--9.5-1.sql +++ b/src/backend/columnar/sql/downgrades/columnar--10.0-1--9.5-1.sql @@ -29,8 +29,8 @@ IF substring(current_Setting('server_version'), '\d+')::int >= 12 THEN END IF; END$proc$; -DROP TABLE columnar_skipnodes; -DROP TABLE columnar_stripes; +DROP TABLE chunk; +DROP TABLE stripe; DROP TABLE options; DROP SEQUENCE storageid_seq; diff --git a/src/backend/columnar/write_state_management.c b/src/backend/columnar/write_state_management.c index 192a4f060..9b0c49dec 100644 --- a/src/backend/columnar/write_state_management.c +++ b/src/backend/columnar/write_state_management.c @@ -116,8 +116,8 @@ CleanupWriteStateMap(void *arg) TableWriteState * -cstore_init_write_state(Relation relation, TupleDesc tupdesc, - SubTransactionId currentSubXid) +columnar_init_write_state(Relation relation, TupleDesc tupdesc, + SubTransactionId currentSubXid) { bool found; @@ -182,9 +182,9 @@ cstore_init_write_state(Relation relation, TupleDesc tupdesc, ReadColumnarOptions(relation->rd_id, &cstoreOptions); SubXidWriteState *stackEntry = palloc0(sizeof(SubXidWriteState)); - stackEntry->writeState = CStoreBeginWrite(relation->rd_node, - cstoreOptions, - tupdesc); + stackEntry->writeState = ColumnarBeginWrite(relation->rd_node, + cstoreOptions, + tupdesc); stackEntry->subXid = currentSubXid; stackEntry->next = hashEntry->writeStateStack; hashEntry->writeStateStack = stackEntry; @@ -215,7 +215,7 @@ FlushWriteStateForRelfilenode(Oid relfilenode, SubTransactionId currentSubXid) SubXidWriteState *stackEntry = entry->writeStateStack; if (stackEntry->subXid == currentSubXid) { - CStoreFlushPendingWrites(stackEntry->writeState); + ColumnarFlushPendingWrites(stackEntry->writeState); } } } @@ -279,7 +279,7 @@ PopWriteStateForAllRels(SubTransactionId currentSubXid, SubTransactionId parentS { if (commit) { - CStoreEndWrite(stackHead->writeState); + ColumnarEndWrite(stackHead->writeState); } entry->writeStateStack = stackHead->next; diff --git a/src/backend/distributed/commands/create_citus_local_table.c b/src/backend/distributed/commands/create_citus_local_table.c index 4950649c7..41f988450 100644 --- a/src/backend/distributed/commands/create_citus_local_table.c +++ b/src/backend/distributed/commands/create_citus_local_table.c @@ -26,6 +26,7 @@ #include "distributed/commands/sequence.h" #include "distributed/commands/utility_hook.h" #include "distributed/listutils.h" +#include "distributed/local_executor.h" #include "distributed/metadata_sync.h" #include "distributed/multi_partitioning_utils.h" #include "distributed/namespace_utils.h" @@ -118,6 +119,14 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys) /* enable create_citus_local_table on an empty node */ InsertCoordinatorIfClusterEmpty(); + /* + * Creating Citus local tables relies on functions that accesses + * shards locally (e.g., ExecuteAndLogDDLCommand()). As long as + * we don't teach those functions to access shards remotely, we + * cannot relax this check. + */ + SetLocalExecutionStatus(LOCAL_EXECUTION_REQUIRED); + /* * Lock target relation with an AccessExclusiveLock as we don't want * multiple backends manipulating this relation. We could actually simply diff --git a/src/backend/distributed/operations/node_protocol.c b/src/backend/distributed/operations/node_protocol.c index e794ef7e9..8097c081a 100644 --- a/src/backend/distributed/operations/node_protocol.c +++ b/src/backend/distributed/operations/node_protocol.c @@ -660,7 +660,7 @@ GetPreLoadTableCreationCommands(Oid relationId, bool includeSequenceDefaults, #if PG_VERSION_NUM >= 120000 /* add columnar options for cstore tables */ - if (accessMethod == NULL && IsCStoreTableAmTable(relationId)) + if (accessMethod == NULL && IsColumnarTableAmTable(relationId)) { TableDDLCommand *cstoreOptionsDDL = ColumnarGetTableOptionsDDL(relationId); if (cstoreOptionsDDL != NULL) diff --git a/src/include/columnar/cstore.h b/src/include/columnar/cstore.h index 6548887a0..a1fe6ff55 100644 --- a/src/include/columnar/cstore.h +++ b/src/include/columnar/cstore.h @@ -2,7 +2,7 @@ * * cstore.h * - * Type and function declarations for CStore + * Type and function declarations for Columnar * * Copyright (c) 2016, Citus Data, Inc. * @@ -41,7 +41,7 @@ #define COMPRESSION_STRING_NONE "none" #define COMPRESSION_STRING_PG_LZ "pglz" -/* CStore file signature */ +/* Columnar file signature */ #define CSTORE_MAGIC_NUMBER "citus_cstore" #define CSTORE_VERSION_MAJOR 1 #define CSTORE_VERSION_MINOR 7 @@ -236,6 +236,7 @@ typedef struct TableReadState StripeBuffers *stripeBuffers; uint32 readStripeCount; uint64 stripeReadRowCount; + int64 chunksFiltered; ChunkData *chunkData; int32 deserializedChunkIndex; } TableReadState; @@ -264,34 +265,34 @@ typedef struct TableWriteState StringInfo compressionBuffer; } TableWriteState; -extern int cstore_compression; -extern int cstore_stripe_row_count; -extern int cstore_chunk_row_count; +extern int columnar_compression; +extern int columnar_stripe_row_count; +extern int columnar_chunk_row_count; extern int columnar_compression_level; -extern void cstore_init(void); +extern void columnar_init_gucs(void); extern CompressionType ParseCompressionType(const char *compressionTypeString); /* Function declarations for writing to a cstore file */ -extern TableWriteState * CStoreBeginWrite(RelFileNode relfilenode, - ColumnarOptions options, - TupleDesc tupleDescriptor); -extern void CStoreWriteRow(TableWriteState *state, Datum *columnValues, - bool *columnNulls); -extern void CStoreFlushPendingWrites(TableWriteState *state); -extern void CStoreEndWrite(TableWriteState *state); +extern TableWriteState * ColumnarBeginWrite(RelFileNode relfilenode, + ColumnarOptions options, + TupleDesc tupleDescriptor); +extern void ColumnarWriteRow(TableWriteState *state, Datum *columnValues, + bool *columnNulls); +extern void ColumnarFlushPendingWrites(TableWriteState *state); +extern void ColumnarEndWrite(TableWriteState *state); extern bool ContainsPendingWrites(TableWriteState *state); /* Function declarations for reading from a cstore file */ -extern TableReadState * CStoreBeginRead(Relation relation, - TupleDesc tupleDescriptor, - List *projectedColumnList, List *qualConditions); -extern bool CStoreReadFinished(TableReadState *state); -extern bool CStoreReadNextRow(TableReadState *state, Datum *columnValues, - bool *columnNulls); -extern void CStoreRescan(TableReadState *readState); -extern void CStoreEndRead(TableReadState *state); +extern TableReadState * ColumnarBeginRead(Relation relation, + TupleDesc tupleDescriptor, + List *projectedColumnList, + List *qualConditions); +extern bool ColumnarReadNextRow(TableReadState *state, Datum *columnValues, + bool *columnNulls); +extern void ColumnarRescan(TableReadState *readState); +extern void ColumnarEndRead(TableReadState *state); /* Function declarations for common functions */ extern FmgrInfo * GetFunctionInfoOrNull(Oid typeId, Oid accessMethodId, @@ -299,7 +300,7 @@ extern FmgrInfo * GetFunctionInfoOrNull(Oid typeId, Oid accessMethodId, extern ChunkData * CreateEmptyChunkData(uint32 columnCount, bool *columnMask, uint32 chunkRowCount); extern void FreeChunkData(ChunkData *chunkData); -extern uint64 CStoreTableRowCount(Relation relation); +extern uint64 ColumnarTableRowCount(Relation relation); extern bool CompressBuffer(StringInfo inputBuffer, StringInfo outputBuffer, CompressionType compressionType, @@ -308,7 +309,7 @@ extern StringInfo DecompressBuffer(StringInfo buffer, CompressionType compressio uint64 decompressedSize); extern const char * CompressionTypeStr(CompressionType type); -/* cstore_metadata_tables.c */ +/* columnar_metadata_tables.c */ extern void InitColumnarOptions(Oid regclass); extern void SetColumnarOptions(Oid regclass, ColumnarOptions *options); extern bool DeleteColumnarTableOptions(Oid regclass, bool missingOk); @@ -316,9 +317,9 @@ extern bool ReadColumnarOptions(Oid regclass, ColumnarOptions *options); extern void WriteToSmgr(Relation relation, uint64 logicalOffset, char *data, uint32 dataLength); extern StringInfo ReadFromSmgr(Relation rel, uint64 offset, uint32 size); -extern bool IsCStoreTableAmTable(Oid relationId); +extern bool IsColumnarTableAmTable(Oid relationId); -/* cstore_metadata_tables.c */ +/* columnar_metadata_tables.c */ extern void DeleteMetadataRows(RelFileNode relfilenode); extern List * StripesForRelfilenode(RelFileNode relfilenode); extern uint64 GetHighestUsedAddress(RelFileNode relfilenode); @@ -335,9 +336,9 @@ extern Datum columnar_relation_storageid(PG_FUNCTION_ARGS); /* write_state_management.c */ -extern TableWriteState * cstore_init_write_state(Relation relation, TupleDesc - tupdesc, - SubTransactionId currentSubXid); +extern TableWriteState * columnar_init_write_state(Relation relation, TupleDesc + tupdesc, + SubTransactionId currentSubXid); extern void FlushWriteStateForRelfilenode(Oid relfilenode, SubTransactionId currentSubXid); extern void FlushWriteStateForAllRels(SubTransactionId currentSubXid, SubTransactionId diff --git a/src/include/columnar/cstore_customscan.h b/src/include/columnar/cstore_customscan.h index 46d71b4ac..63b5a3523 100644 --- a/src/include/columnar/cstore_customscan.h +++ b/src/include/columnar/cstore_customscan.h @@ -13,7 +13,7 @@ #ifndef COLUMNAR_CUSTOMSCAN_H #define COLUMNAR_CUSTOMSCAN_H -void cstore_customscan_init(void); +void columnar_customscan_init(void); #endif /* COLUMNAR_CUSTOMSCAN_H */ diff --git a/src/include/columnar/cstore_tableam.h b/src/include/columnar/cstore_tableam.h index 71f223678..0d066a2e0 100644 --- a/src/include/columnar/cstore_tableam.h +++ b/src/include/columnar/cstore_tableam.h @@ -10,16 +10,16 @@ #include "distributed/coordinator_protocol.h" const TableAmRoutine * GetColumnarTableAmRoutine(void); -extern void cstore_tableam_init(void); -extern void cstore_tableam_finish(void); +extern void columnar_tableam_init(void); +extern void columnar_tableam_finish(void); -extern TableScanDesc cstore_beginscan_extended(Relation relation, Snapshot snapshot, - int nkeys, ScanKey key, - ParallelTableScanDesc parallel_scan, - uint32 flags, Bitmapset *attr_needed, - List *scanQual); - -extern bool IsCStoreTableAmTable(Oid relationId); +extern TableScanDesc columnar_beginscan_extended(Relation relation, Snapshot snapshot, + int nkeys, ScanKey key, + ParallelTableScanDesc parallel_scan, + uint32 flags, Bitmapset *attr_needed, + List *scanQual); +extern int64 ColumnarGetChunksFiltered(TableScanDesc scanDesc); +extern bool IsColumnarTableAmTable(Oid relationId); extern TableDDLCommand * ColumnarGetTableOptionsDDL(Oid relationId); extern char * GetShardedTableDDLCommandColumnar(uint64 shardId, void *context); #endif diff --git a/src/test/regress/expected/am_drop.out b/src/test/regress/expected/am_drop.out index 3d244b487..ecb5fea0a 100644 --- a/src/test/regress/expected/am_drop.out +++ b/src/test/regress/expected/am_drop.out @@ -12,12 +12,12 @@ -- 'postgres' directory is excluded from comparison to have the same result. -- store postgres database oid SELECT oid postgres_oid FROM pg_database WHERE datname = 'postgres' \gset -SELECT count(distinct storageid) AS columnar_stripes_before_drop FROM columnar.columnar_stripes \gset +SELECT count(distinct storageid) AS columnar_stripes_before_drop FROM columnar.stripe \gset -- DROP columnar tables DROP TABLE contestant; DROP TABLE contestant_compressed; -- make sure DROP deletes metadata -SELECT :columnar_stripes_before_drop - count(distinct storageid) FROM columnar.columnar_stripes; +SELECT :columnar_stripes_before_drop - count(distinct storageid) FROM columnar.stripe; ?column? --------------------------------------------------------------------- 2 @@ -27,10 +27,10 @@ SELECT :columnar_stripes_before_drop - count(distinct storageid) FROM columnar.c CREATE SCHEMA test_schema; CREATE TABLE test_schema.test_table(data int) USING columnar; INSERT INTO test_schema.test_table VALUES (1); -SELECT count(*) AS columnar_stripes_before_drop FROM columnar.columnar_stripes \gset +SELECT count(*) AS columnar_stripes_before_drop FROM columnar.stripe \gset DROP SCHEMA test_schema CASCADE; NOTICE: drop cascades to table test_schema.test_table -SELECT :columnar_stripes_before_drop - count(distinct storageid) FROM columnar.columnar_stripes; +SELECT :columnar_stripes_before_drop - count(distinct storageid) FROM columnar.stripe; ?column? --------------------------------------------------------------------- 1 diff --git a/src/test/regress/expected/am_matview.out b/src/test/regress/expected/am_matview.out index 54f69f375..579fb01fc 100644 --- a/src/test/regress/expected/am_matview.out +++ b/src/test/regress/expected/am_matview.out @@ -68,13 +68,13 @@ SELECT * FROM t_view a ORDER BY a; -- verify that we have created metadata entries for the materialized view SELECT columnar_relation_storageid(oid) AS storageid FROM pg_class WHERE relname='t_view' \gset -SELECT count(*) FROM columnar.columnar_stripes WHERE storageid=:storageid; +SELECT count(*) FROM columnar.stripe WHERE storageid=:storageid; count --------------------------------------------------------------------- 1 (1 row) -SELECT count(*) FROM columnar.columnar_skipnodes WHERE storageid=:storageid; +SELECT count(*) FROM columnar.chunk WHERE storageid=:storageid; count --------------------------------------------------------------------- 3 @@ -83,13 +83,13 @@ SELECT count(*) FROM columnar.columnar_skipnodes WHERE storageid=:storageid; DROP TABLE t CASCADE; NOTICE: drop cascades to materialized view t_view -- dropping must remove metadata -SELECT count(*) FROM columnar.columnar_stripes WHERE storageid=:storageid; +SELECT count(*) FROM columnar.stripe WHERE storageid=:storageid; count --------------------------------------------------------------------- 0 (1 row) -SELECT count(*) FROM columnar.columnar_skipnodes WHERE storageid=:storageid; +SELECT count(*) FROM columnar.chunk WHERE storageid=:storageid; count --------------------------------------------------------------------- 0 diff --git a/src/test/regress/expected/am_recursive.out b/src/test/regress/expected/am_recursive.out index 88ea9eca1..df1fca496 100644 --- a/src/test/regress/expected/am_recursive.out +++ b/src/test/regress/expected/am_recursive.out @@ -11,7 +11,7 @@ $$ LANGUAGE SQL; INSERT INTO t2 SELECT i, f(i) FROM generate_series(1, 5) i; -- there are no subtransactions, so above statement should batch -- INSERTs inside the UDF and create on stripe per table. -SELECT relname, count(*) FROM columnar.columnar_stripes a, pg_class b +SELECT relname, count(*) FROM columnar.stripe a, pg_class b WHERE columnar_relation_storageid(b.oid)=a.storageid AND relname IN ('t1', 't2') GROUP BY relname ORDER BY relname; diff --git a/src/test/regress/expected/am_rollback.out b/src/test/regress/expected/am_rollback.out index 2b5d26ed3..a862f1d65 100644 --- a/src/test/regress/expected/am_rollback.out +++ b/src/test/regress/expected/am_rollback.out @@ -3,7 +3,7 @@ -- CREATE TABLE t(a int, b int) USING columnar; CREATE VIEW t_stripes AS -SELECT * FROM columnar.columnar_stripes a, pg_class b +SELECT * FROM columnar.stripe a, pg_class b WHERE a.storageid = columnar_relation_storageid(b.oid) AND b.relname = 't'; BEGIN; INSERT INTO t SELECT i, i+1 FROM generate_series(1, 10) i; diff --git a/src/test/regress/expected/am_truncate.out b/src/test/regress/expected/am_truncate.out index bdd4946bb..7536e037b 100644 --- a/src/test/regress/expected/am_truncate.out +++ b/src/test/regress/expected/am_truncate.out @@ -15,7 +15,7 @@ CREATE TABLE columnar_truncate_test_second (a int, b int) USING columnar; -- COMPRESSED CREATE TABLE columnar_truncate_test_compressed (a int, b int) USING columnar; CREATE TABLE columnar_truncate_test_regular (a int, b int); -SELECT count(distinct storageid) AS columnar_data_files_before_truncate FROM columnar.columnar_stripes \gset +SELECT count(distinct storageid) AS columnar_data_files_before_truncate FROM columnar.stripe \gset INSERT INTO columnar_truncate_test select a, a from generate_series(1, 10) a; set columnar.compression = 'pglz'; INSERT INTO columnar_truncate_test_compressed select a, a from generate_series(1, 10) a; @@ -147,7 +147,7 @@ SELECT * from columnar_truncate_test; (0 rows) -- make sure TRUNATE deletes metadata for old relfilenode -SELECT :columnar_data_files_before_truncate - count(distinct storageid) FROM columnar.columnar_stripes; +SELECT :columnar_data_files_before_truncate - count(distinct storageid) FROM columnar.stripe; ?column? --------------------------------------------------------------------- 0 @@ -161,7 +161,7 @@ TRUNCATE columnar_same_transaction_truncate; INSERT INTO columnar_same_transaction_truncate SELECT * FROM generate_series(20, 23); COMMIT; -- should output "1" for the newly created relation -SELECT count(distinct storageid) - :columnar_data_files_before_truncate FROM columnar.columnar_stripes; +SELECT count(distinct storageid) - :columnar_data_files_before_truncate FROM columnar.stripe; ?column? --------------------------------------------------------------------- 1 diff --git a/src/test/regress/expected/am_vacuum.out b/src/test/regress/expected/am_vacuum.out index a2963d7d8..23d328d5f 100644 --- a/src/test/regress/expected/am_vacuum.out +++ b/src/test/regress/expected/am_vacuum.out @@ -1,8 +1,8 @@ SET columnar.compression TO 'none'; -SELECT count(distinct storageid) AS columnar_table_count FROM columnar.columnar_stripes \gset +SELECT count(distinct storageid) AS columnar_table_count FROM columnar.stripe \gset CREATE TABLE t(a int, b int) USING columnar; CREATE VIEW t_stripes AS -SELECT * FROM columnar.columnar_stripes a, pg_class b +SELECT * FROM columnar.stripe a, pg_class b WHERE a.storageid = columnar_relation_storageid(b.oid) AND b.relname='t'; SELECT count(*) FROM t_stripes; count @@ -74,35 +74,35 @@ SELECT count(*) FROM t_stripes; -- VACUUM FULL doesn't reclaim dropped columns, but converts them to NULLs ALTER TABLE t DROP COLUMN a; -SELECT stripe, attr, chunk, minimum_value IS NULL, maximum_value IS NULL -FROM columnar.columnar_skipnodes a, pg_class b +SELECT stripeid, attnum, chunkid, minimum_value IS NULL, maximum_value IS NULL +FROM columnar.chunk a, pg_class b WHERE a.storageid = columnar_relation_storageid(b.oid) AND b.relname='t' ORDER BY 1, 2, 3; - stripe | attr | chunk | ?column? | ?column? + stripeid | attnum | chunkid | ?column? | ?column? --------------------------------------------------------------------- - 1 | 1 | 0 | f | f - 1 | 2 | 0 | f | f - 2 | 1 | 0 | f | f - 2 | 2 | 0 | f | f - 3 | 1 | 0 | f | f - 3 | 2 | 0 | f | f + 1 | 1 | 0 | f | f + 1 | 2 | 0 | f | f + 2 | 1 | 0 | f | f + 2 | 2 | 0 | f | f + 3 | 1 | 0 | f | f + 3 | 2 | 0 | f | f (6 rows) VACUUM FULL t; -SELECT stripe, attr, chunk, minimum_value IS NULL, maximum_value IS NULL -FROM columnar.columnar_skipnodes a, pg_class b +SELECT stripeid, attnum, chunkid, minimum_value IS NULL, maximum_value IS NULL +FROM columnar.chunk a, pg_class b WHERE a.storageid = columnar_relation_storageid(b.oid) AND b.relname='t' ORDER BY 1, 2, 3; - stripe | attr | chunk | ?column? | ?column? + stripeid | attnum | chunkid | ?column? | ?column? --------------------------------------------------------------------- - 1 | 1 | 0 | t | t - 1 | 2 | 0 | f | f - 2 | 1 | 0 | t | t - 2 | 2 | 0 | f | f - 3 | 1 | 0 | t | t - 3 | 2 | 0 | f | f + 1 | 1 | 0 | t | t + 1 | 2 | 0 | f | f + 2 | 1 | 0 | t | t + 2 | 2 | 0 | f | f + 3 | 1 | 0 | t | t + 3 | 2 | 0 | f | f (6 rows) -- Make sure we cleaned-up the transient table metadata after VACUUM FULL commands -SELECT count(distinct storageid) - :columnar_table_count FROM columnar.columnar_stripes; +SELECT count(distinct storageid) - :columnar_table_count FROM columnar.stripe; ?column? --------------------------------------------------------------------- 1 @@ -242,7 +242,7 @@ chunk count: 8, containing data for dropped columns: 0, none compressed: 2, pglz DROP TABLE t; DROP VIEW t_stripes; -- Make sure we cleaned the metadata for t too -SELECT count(distinct storageid) - :columnar_table_count FROM columnar.columnar_stripes; +SELECT count(distinct storageid) - :columnar_table_count FROM columnar.stripe; ?column? --------------------------------------------------------------------- 0 diff --git a/src/test/regress/expected/citus_local_table_triggers.out b/src/test/regress/expected/citus_local_table_triggers.out index b85442e0b..beb44213e 100644 --- a/src/test/regress/expected/citus_local_table_triggers.out +++ b/src/test/regress/expected/citus_local_table_triggers.out @@ -14,13 +14,20 @@ SELECT 1 FROM master_add_node('localhost', :master_port, groupId => 0); (1 row) RESET client_min_messages; -CREATE TABLE citus_local_table (value int); -SELECT create_citus_local_table('citus_local_table'); - create_citus_local_table +CREATE TABLE dummy_reference_table(a int unique, b int); +INSERT INTO dummy_reference_table SELECT i FROM generate_series(-1, 5) i; +INSERT INTO dummy_reference_table VALUES (99),(100),(599),(600); +SELECT create_reference_table('dummy_reference_table'); +NOTICE: Copying data from local table... +NOTICE: copying the data has completed + create_reference_table --------------------------------------------------------------------- (1 row) +CREATE TABLE citus_local_table (value int); +ALTER TABLE citus_local_table ADD CONSTRAINT fkey_to_dummy_1 FOREIGN KEY (value) REFERENCES dummy_reference_table(a); +NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1507001, 'citus_local_table_triggers', 1507000, 'citus_local_table_triggers', 'ALTER TABLE citus_local_table ADD CONSTRAINT fkey_to_dummy_1 FOREIGN KEY (value) REFERENCES dummy_reference_table(a);') --------------------------------------------------------------------- -- DELETE trigger -- --------------------------------------------------------------------- @@ -41,13 +48,13 @@ BEGIN; CREATE TRIGGER insert_42_trigger AFTER DELETE ON citus_local_table FOR EACH ROW EXECUTE FUNCTION insert_42(); -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507000, 'citus_local_table_triggers', 'CREATE TRIGGER insert_42_trigger +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507001, 'citus_local_table_triggers', 'CREATE TRIGGER insert_42_trigger AFTER DELETE ON citus_local_table FOR EACH ROW EXECUTE FUNCTION insert_42();') -- select should print two rows with "42" as delete from citus_local_table will -- insert 42 per deleted row DELETE FROM citus_local_table; -NOTICE: executing the command locally: DELETE FROM citus_local_table_triggers.citus_local_table_1507000 citus_local_table +NOTICE: executing the command locally: DELETE FROM citus_local_table_triggers.citus_local_table_1507001 citus_local_table SELECT * FROM distributed_table; value --------------------------------------------------------------------- @@ -60,7 +67,7 @@ ROLLBACK; BEGIN; CREATE TABLE reference_table(value int); SELECT create_reference_table('reference_table'); -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507005, 'citus_local_table_triggers', 'CREATE TABLE citus_local_table_triggers.reference_table (value integer)');SELECT worker_apply_shard_ddl_command (1507005, 'citus_local_table_triggers', 'ALTER TABLE citus_local_table_triggers.reference_table OWNER TO postgres') +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507006, 'citus_local_table_triggers', 'CREATE TABLE citus_local_table_triggers.reference_table (value integer) ');SELECT worker_apply_shard_ddl_command (1507006, 'citus_local_table_triggers', 'ALTER TABLE citus_local_table_triggers.reference_table OWNER TO postgres') create_reference_table --------------------------------------------------------------------- @@ -79,10 +86,10 @@ NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1 -- are executed only for once. -- select should print a row with "100" as truncate from citus_local_table will insert 100 TRUNCATE citus_local_table; -NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.reference_table_1507005 (value) VALUES (100) +NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.reference_table_1507006 (value) VALUES (100) NOTICE: executing the command locally: TRUNCATE TABLE citus_local_table_triggers.citus_local_table_xxxxx CASCADE SELECT * FROM reference_table; -NOTICE: executing the command locally: SELECT value FROM citus_local_table_triggers.reference_table_1507005 reference_table +NOTICE: executing the command locally: SELECT value FROM citus_local_table_triggers.reference_table_1507006 reference_table value --------------------------------------------------------------------- 100 @@ -103,7 +110,7 @@ BEGIN; CREATE TRIGGER increment_value_trigger AFTER INSERT ON citus_local_table FOR EACH ROW EXECUTE FUNCTION increment_value(); -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507000, 'citus_local_table_triggers', 'CREATE TRIGGER increment_value_trigger +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507001, 'citus_local_table_triggers', 'CREATE TRIGGER increment_value_trigger AFTER INSERT ON citus_local_table FOR EACH ROW EXECUTE FUNCTION increment_value();') -- insert initial data to the table that increment_value_trigger will execute for @@ -111,7 +118,7 @@ NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1 -- select should print a row with "2" as insert into citus_local_table will -- increment all rows per inserted row INSERT INTO citus_local_table VALUES(0), (1); -NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.citus_local_table_1507000 AS citus_table_alias (value) VALUES (0), (1) +NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.citus_local_table_1507001 AS citus_table_alias (value) VALUES (0), (1) SELECT * FROM local_table; value --------------------------------------------------------------------- @@ -133,14 +140,14 @@ BEGIN; CREATE TRIGGER error_for_5_trigger BEFORE UPDATE OF value ON citus_local_table FOR EACH ROW EXECUTE FUNCTION error_for_5(); -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507000, 'citus_local_table_triggers', 'CREATE TRIGGER error_for_5_trigger +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507001, 'citus_local_table_triggers', 'CREATE TRIGGER error_for_5_trigger BEFORE UPDATE OF value ON citus_local_table FOR EACH ROW EXECUTE FUNCTION error_for_5();') -- below update will error out as trigger raises exception INSERT INTO citus_local_table VALUES (5); -NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.citus_local_table_1507000 (value) VALUES (5) +NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.citus_local_table_1507001 (value) VALUES (5) UPDATE citus_local_table SET value=value*2 WHERE value=5; -NOTICE: executing the command locally: UPDATE citus_local_table_triggers.citus_local_table_1507000 citus_local_table SET value = (value OPERATOR(pg_catalog.*) 2) WHERE (value OPERATOR(pg_catalog.=) 5) +NOTICE: executing the command locally: UPDATE citus_local_table_triggers.citus_local_table_1507001 citus_local_table SET value = (value OPERATOR(pg_catalog.*) 2) WHERE (value OPERATOR(pg_catalog.=) 5) ERROR: cannot update update for value=5 ROLLBACK; --------------------------------------------------------------------- @@ -165,14 +172,11 @@ BEGIN; CREATE TRIGGER initial_truncate_trigger AFTER TRUNCATE ON "interesting!schema"."citus_local!_table" FOR EACH STATEMENT EXECUTE FUNCTION dummy_function(); - SELECT create_citus_local_table('"interesting!schema"."citus_local!_table"'); - create_citus_local_table ---------------------------------------------------------------------- - -(1 row) - + ALTER TABLE "interesting!schema"."citus_local!_table" ADD CONSTRAINT fkey_to_dummy_2 FOREIGN KEY (value) REFERENCES dummy_reference_table(a); +NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1507007, 'interesting!schema', 1507000, 'citus_local_table_triggers', 'ALTER TABLE "interesting!schema"."citus_local!_table" ADD CONSTRAINT fkey_to_dummy_2 FOREIGN KEY (value) REFERENCES dummy_reference_table(a);') -- we shouldn't see truncate trigger on shard relation as we drop it - SELECT * FROM citus_local_table_triggers; + SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; tgname | tgrelid | tgenabled --------------------------------------------------------------------- initial_truncate_trigger | "interesting!schema"."citus_local!_table" | O @@ -181,23 +185,19 @@ BEGIN; ROLLBACK; CREATE TABLE "interesting!schema"."citus_local!_table"(value int); -SELECT create_citus_local_table('"interesting!schema"."citus_local!_table"'); - create_citus_local_table ---------------------------------------------------------------------- - -(1 row) - +ALTER TABLE "interesting!schema"."citus_local!_table" ADD CONSTRAINT fkey_to_dummy_2 FOREIGN KEY (value) REFERENCES dummy_reference_table(a); +NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1507008, 'interesting!schema', 1507000, 'citus_local_table_triggers', 'ALTER TABLE "interesting!schema"."citus_local!_table" ADD CONSTRAINT fkey_to_dummy_2 FOREIGN KEY (value) REFERENCES dummy_reference_table(a);') CREATE TRIGGER "trigger\'name" BEFORE INSERT ON "interesting!schema"."citus_local!_table" FOR EACH STATEMENT EXECUTE FUNCTION dummy_function(); -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507007, 'interesting!schema', E'CREATE TRIGGER "trigger\\''name" +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'interesting!schema', E'CREATE TRIGGER "trigger\\''name" BEFORE INSERT ON "interesting!schema"."citus_local!_table" FOR EACH STATEMENT EXECUTE FUNCTION dummy_function();') BEGIN; CREATE EXTENSION seg; -- ALTER TRIGGER DEPENDS ON ALTER TRIGGER "trigger\'name" ON "interesting!schema"."citus_local!_table" DEPENDS ON EXTENSION seg; -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507007, 'interesting!schema', E'ALTER TRIGGER "trigger\\''name" ON "interesting!schema"."citus_local!_table" DEPENDS ON EXTENSION seg;') +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'interesting!schema', E'ALTER TRIGGER "trigger\\''name" ON "interesting!schema"."citus_local!_table" DEPENDS ON EXTENSION seg;') -- show that triggers on both shell relation and shard relation are depending on seg SELECT tgname FROM pg_depend, pg_trigger, pg_extension WHERE deptype = 'x' and classid='pg_trigger'::regclass and @@ -206,12 +206,13 @@ NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1 tgname --------------------------------------------------------------------- trigger\'name - trigger\'name_1507007 + trigger\'name_1507008 (2 rows) DROP EXTENSION seg; -- show that dropping extension drops the triggers automatically - SELECT * FROM citus_local_table_triggers; + SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; tgname | tgrelid | tgenabled --------------------------------------------------------------------- truncate_trigger_xxxxxxx | "interesting!schema"."citus_local!_table" | O @@ -220,102 +221,110 @@ NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1 ROLLBACK; -- ALTER TRIGGER RENAME ALTER TRIGGER "trigger\'name" ON "interesting!schema"."citus_local!_table" RENAME TO "trigger\'name22"; -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507007, 'interesting!schema', E'ALTER TRIGGER "trigger\\''name" ON "interesting!schema"."citus_local!_table" RENAME TO "trigger\\''name22";') +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'interesting!schema', E'ALTER TRIGGER "trigger\\''name" ON "interesting!schema"."citus_local!_table" RENAME TO "trigger\\''name22";') -- show that triggers on both shell relation and shard relation are renamed -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; tgname | tgrelid | tgenabled --------------------------------------------------------------------- trigger\'name22 | "interesting!schema"."citus_local!_table" | O - trigger\'name22_1507007 | "interesting!schema"."citus_local!_table_1507007" | O + trigger\'name22_1507008 | "interesting!schema"."citus_local!_table_1507008" | O truncate_trigger_xxxxxxx | "interesting!schema"."citus_local!_table" | O (3 rows) -- ALTER TABLE DISABLE trigger ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER "trigger\'name22"; -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507007, 'interesting!schema', E'ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER "trigger\\''name22";') -SELECT * FROM citus_local_table_triggers; +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'interesting!schema', E'ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER "trigger\\''name22";') +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; tgname | tgrelid | tgenabled --------------------------------------------------------------------- trigger\'name22 | "interesting!schema"."citus_local!_table" | D - trigger\'name22_1507007 | "interesting!schema"."citus_local!_table_1507007" | D + trigger\'name22_1507008 | "interesting!schema"."citus_local!_table_1507008" | D truncate_trigger_xxxxxxx | "interesting!schema"."citus_local!_table" | O (3 rows) -- ALTER TABLE ENABLE trigger ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER "trigger\'name22"; -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507007, 'interesting!schema', E'ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER "trigger\\''name22";') -SELECT * FROM citus_local_table_triggers; +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'interesting!schema', E'ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER "trigger\\''name22";') +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; tgname | tgrelid | tgenabled --------------------------------------------------------------------- trigger\'name22 | "interesting!schema"."citus_local!_table" | O - trigger\'name22_1507007 | "interesting!schema"."citus_local!_table_1507007" | O + trigger\'name22_1507008 | "interesting!schema"."citus_local!_table_1507008" | O truncate_trigger_xxxxxxx | "interesting!schema"."citus_local!_table" | O (3 rows) CREATE TRIGGER another_trigger AFTER DELETE ON "interesting!schema"."citus_local!_table" FOR EACH STATEMENT EXECUTE FUNCTION dummy_function(); -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507007, 'interesting!schema', 'CREATE TRIGGER another_trigger +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'interesting!schema', 'CREATE TRIGGER another_trigger AFTER DELETE ON "interesting!schema"."citus_local!_table" FOR EACH STATEMENT EXECUTE FUNCTION dummy_function();') ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER USER; -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507007, 'interesting!schema', 'ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER USER;') +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'interesting!schema', 'ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER USER;') -- show that all triggers except the internal ones are disabled -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; tgname | tgrelid | tgenabled --------------------------------------------------------------------- another_trigger | "interesting!schema"."citus_local!_table" | D - another_trigger_1507007 | "interesting!schema"."citus_local!_table_1507007" | D + another_trigger_1507008 | "interesting!schema"."citus_local!_table_1507008" | D trigger\'name22 | "interesting!schema"."citus_local!_table" | D - trigger\'name22_1507007 | "interesting!schema"."citus_local!_table_1507007" | D + trigger\'name22_1507008 | "interesting!schema"."citus_local!_table_1507008" | D truncate_trigger_xxxxxxx | "interesting!schema"."citus_local!_table" | O (5 rows) ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER USER; -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507007, 'interesting!schema', 'ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER USER;') +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'interesting!schema', 'ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER USER;') -- show that all triggers except the internal ones are enabled again -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; tgname | tgrelid | tgenabled --------------------------------------------------------------------- another_trigger | "interesting!schema"."citus_local!_table" | O - another_trigger_1507007 | "interesting!schema"."citus_local!_table_1507007" | O + another_trigger_1507008 | "interesting!schema"."citus_local!_table_1507008" | O trigger\'name22 | "interesting!schema"."citus_local!_table" | O - trigger\'name22_1507007 | "interesting!schema"."citus_local!_table_1507007" | O + trigger\'name22_1507008 | "interesting!schema"."citus_local!_table_1507008" | O truncate_trigger_xxxxxxx | "interesting!schema"."citus_local!_table" | O (5 rows) ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER ALL; -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507007, 'interesting!schema', 'ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER ALL;') +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'interesting!schema', 'ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER ALL;') -- show that all triggers including internal triggers are disabled -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; tgname | tgrelid | tgenabled --------------------------------------------------------------------- another_trigger | "interesting!schema"."citus_local!_table" | D - another_trigger_1507007 | "interesting!schema"."citus_local!_table_1507007" | D + another_trigger_1507008 | "interesting!schema"."citus_local!_table_1507008" | D trigger\'name22 | "interesting!schema"."citus_local!_table" | D - trigger\'name22_1507007 | "interesting!schema"."citus_local!_table_1507007" | D + trigger\'name22_1507008 | "interesting!schema"."citus_local!_table_1507008" | D truncate_trigger_xxxxxxx | "interesting!schema"."citus_local!_table" | D (5 rows) ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER ALL; -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507007, 'interesting!schema', 'ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER ALL;') +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'interesting!schema', 'ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER ALL;') -- show that all triggers including internal triggers are enabled again -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; tgname | tgrelid | tgenabled --------------------------------------------------------------------- another_trigger | "interesting!schema"."citus_local!_table" | O - another_trigger_1507007 | "interesting!schema"."citus_local!_table_1507007" | O + another_trigger_1507008 | "interesting!schema"."citus_local!_table_1507008" | O trigger\'name22 | "interesting!schema"."citus_local!_table" | O - trigger\'name22_1507007 | "interesting!schema"."citus_local!_table_1507007" | O + trigger\'name22_1507008 | "interesting!schema"."citus_local!_table_1507008" | O truncate_trigger_xxxxxxx | "interesting!schema"."citus_local!_table" | O (5 rows) DROP TRIGGER another_trigger ON "interesting!schema"."citus_local!_table"; -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507007, 'interesting!schema', 'DROP TRIGGER another_trigger ON "interesting!schema"."citus_local!_table";') +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'interesting!schema', 'DROP TRIGGER another_trigger ON "interesting!schema"."citus_local!_table";') DROP TRIGGER "trigger\'name22" ON "interesting!schema"."citus_local!_table"; -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507007, 'interesting!schema', E'DROP TRIGGER "trigger\\''name22" ON "interesting!schema"."citus_local!_table";') +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'interesting!schema', E'DROP TRIGGER "trigger\\''name22" ON "interesting!schema"."citus_local!_table";') -- show that drop trigger works as expected -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; tgname | tgrelid | tgenabled --------------------------------------------------------------------- truncate_trigger_xxxxxxx | "interesting!schema"."citus_local!_table" | O @@ -327,7 +336,8 @@ BEGIN; FOR EACH STATEMENT EXECUTE FUNCTION dummy_function(); ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER "another_trigger\'name"; -- show that our truncate trigger is disabled .. - SELECT * FROM citus_local_table_triggers; + SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; tgname | tgrelid | tgenabled --------------------------------------------------------------------- another_trigger\'name | "interesting!schema"."citus_local!_table" | D @@ -335,9 +345,10 @@ BEGIN; (2 rows) ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER ALL; -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507007, 'interesting!schema', 'ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER ALL;') +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'interesting!schema', 'ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER ALL;') -- .. and now it is enabled back - SELECT * FROM citus_local_table_triggers; + SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; tgname | tgrelid | tgenabled --------------------------------------------------------------------- another_trigger\'name | "interesting!schema"."citus_local!_table" | O @@ -365,9 +376,9 @@ SELECT create_citus_local_table('another_citus_local_table'); (1 row) ALTER TABLE another_citus_local_table ADD CONSTRAINT fkey_self FOREIGN KEY(value) REFERENCES another_citus_local_table(value); -NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1507008, 'citus_local_table_triggers', 1507008, 'citus_local_table_triggers', 'ALTER TABLE another_citus_local_table ADD CONSTRAINT fkey_self FOREIGN KEY(value) REFERENCES another_citus_local_table(value);') +NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1507009, 'citus_local_table_triggers', 1507009, 'citus_local_table_triggers', 'ALTER TABLE another_citus_local_table ADD CONSTRAINT fkey_self FOREIGN KEY(value) REFERENCES another_citus_local_table(value);') ALTER TABLE citus_local_table ADD CONSTRAINT fkey_c_to_c FOREIGN KEY(value) REFERENCES another_citus_local_table(value) ON UPDATE CASCADE; -NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1507000, 'citus_local_table_triggers', 1507008, 'citus_local_table_triggers', 'ALTER TABLE citus_local_table ADD CONSTRAINT fkey_c_to_c FOREIGN KEY(value) REFERENCES another_citus_local_table(value) ON UPDATE CASCADE;') +NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1507001, 'citus_local_table_triggers', 1507009, 'citus_local_table_triggers', 'ALTER TABLE citus_local_table ADD CONSTRAINT fkey_c_to_c FOREIGN KEY(value) REFERENCES another_citus_local_table(value) ON UPDATE CASCADE;') CREATE TABLE reference_table(value int); SELECT create_reference_table('reference_table'); create_reference_table @@ -390,14 +401,14 @@ BEGIN; FOR EACH STATEMENT EXECUTE FUNCTION insert_100(); TRUNCATE another_citus_local_table CASCADE; NOTICE: truncate cascades to table "citus_local_table" -NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.reference_table_1507009 (value) VALUES (100) +NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.reference_table_1507010 (value) VALUES (100) NOTICE: executing the command locally: TRUNCATE TABLE citus_local_table_triggers.another_citus_local_table_xxxxx CASCADE NOTICE: truncate cascades to table "citus_local_table_xxxxx" -NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.reference_table_1507009 (value) VALUES (100) +NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.reference_table_1507010 (value) VALUES (100) NOTICE: executing the command locally: TRUNCATE TABLE citus_local_table_triggers.citus_local_table_xxxxx CASCADE -- we should see two rows with "100" SELECT * FROM reference_table; -NOTICE: executing the command locally: SELECT value FROM citus_local_table_triggers.reference_table_1507009 reference_table +NOTICE: executing the command locally: SELECT value FROM citus_local_table_triggers.reference_table_1507010 reference_table value --------------------------------------------------------------------- 100 @@ -408,28 +419,28 @@ ROLLBACK; BEGIN; -- update should actually update something to test ON UPDATE CASCADE logic INSERT INTO another_citus_local_table VALUES (600); -NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.another_citus_local_table_1507008 (value) VALUES (600) +NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.another_citus_local_table_1507009 (value) VALUES (600) INSERT INTO citus_local_table VALUES (600); -NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.citus_local_table_1507000 (value) VALUES (600) +NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.citus_local_table_1507001 (value) VALUES (600) CREATE TRIGGER insert_100_trigger AFTER UPDATE ON another_citus_local_table FOR EACH STATEMENT EXECUTE FUNCTION insert_100(); -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507008, 'citus_local_table_triggers', 'CREATE TRIGGER insert_100_trigger +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507009, 'citus_local_table_triggers', 'CREATE TRIGGER insert_100_trigger AFTER UPDATE ON another_citus_local_table FOR EACH STATEMENT EXECUTE FUNCTION insert_100();') CREATE TRIGGER insert_100_trigger AFTER UPDATE ON citus_local_table FOR EACH STATEMENT EXECUTE FUNCTION insert_100(); -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507000, 'citus_local_table_triggers', 'CREATE TRIGGER insert_100_trigger +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1507001, 'citus_local_table_triggers', 'CREATE TRIGGER insert_100_trigger AFTER UPDATE ON citus_local_table FOR EACH STATEMENT EXECUTE FUNCTION insert_100();') UPDATE another_citus_local_table SET value=value-1;; -NOTICE: executing the command locally: UPDATE citus_local_table_triggers.another_citus_local_table_1507008 another_citus_local_table SET value = (value OPERATOR(pg_catalog.-) 1) -NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.reference_table_1507009 (value) VALUES (100) -NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.reference_table_1507009 (value) VALUES (100) +NOTICE: executing the command locally: UPDATE citus_local_table_triggers.another_citus_local_table_1507009 another_citus_local_table SET value = (value OPERATOR(pg_catalog.-) 1) +NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.reference_table_1507010 (value) VALUES (100) +NOTICE: executing the command locally: INSERT INTO citus_local_table_triggers.reference_table_1507010 (value) VALUES (100) -- we should see two rows with "100" SELECT * FROM reference_table; -NOTICE: executing the command locally: SELECT value FROM citus_local_table_triggers.reference_table_1507009 reference_table +NOTICE: executing the command locally: SELECT value FROM citus_local_table_triggers.reference_table_1507010 reference_table value --------------------------------------------------------------------- 100 @@ -439,4 +450,4 @@ NOTICE: executing the command locally: SELECT value FROM citus_local_table_trig ROLLBACK; -- cleanup at exit DROP SCHEMA citus_local_table_triggers, "interesting!schema" CASCADE; -NOTICE: drop cascades to 11 other objects +NOTICE: drop cascades to 13 other objects diff --git a/src/test/regress/expected/citus_local_tables_queries.out b/src/test/regress/expected/citus_local_tables_queries.out index 34f254912..581e7437f 100644 --- a/src/test/regress/expected/citus_local_tables_queries.out +++ b/src/test/regress/expected/citus_local_tables_queries.out @@ -14,20 +14,19 @@ SELECT 1 FROM master_add_node('localhost', :master_port, groupId => 0); (1 row) RESET client_min_messages; +CREATE TABLE dummy_reference_table(a int unique, b int); +SELECT create_reference_table('dummy_reference_table'); + create_reference_table +--------------------------------------------------------------------- + +(1 row) + CREATE TABLE citus_local_table(a int, b int); -SELECT create_citus_local_table('citus_local_table'); - create_citus_local_table ---------------------------------------------------------------------- - -(1 row) - +ALTER TABLE citus_local_table ADD CONSTRAINT fkey_to_dummy_1 FOREIGN KEY (a) REFERENCES dummy_reference_table(a); +NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1509001, 'citus_local_table_queries', 1509000, 'citus_local_table_queries', 'ALTER TABLE citus_local_table ADD CONSTRAINT fkey_to_dummy_1 FOREIGN KEY (a) REFERENCES dummy_reference_table(a);') CREATE TABLE citus_local_table_2(a int, b int); -SELECT create_citus_local_table('citus_local_table_2'); - create_citus_local_table ---------------------------------------------------------------------- - -(1 row) - +ALTER TABLE citus_local_table_2 ADD CONSTRAINT fkey_to_dummy_2 FOREIGN KEY (a) REFERENCES dummy_reference_table(a); +NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1509002, 'citus_local_table_queries', 1509000, 'citus_local_table_queries', 'ALTER TABLE citus_local_table_2 ADD CONSTRAINT fkey_to_dummy_2 FOREIGN KEY (a) REFERENCES dummy_reference_table(a);') CREATE TABLE reference_table(a int, b int); SELECT create_reference_table('reference_table'); create_reference_table @@ -53,8 +52,9 @@ CREATE FUNCTION clear_and_init_test_tables() RETURNS void AS $$ BEGIN SET client_min_messages to ERROR; - TRUNCATE postgres_local_table, citus_local_table, reference_table, distributed_table; + TRUNCATE postgres_local_table, citus_local_table, reference_table, distributed_table, dummy_reference_table, citus_local_table_2; + INSERT INTO dummy_reference_table SELECT i, i FROM generate_series(0, 5) i; INSERT INTO citus_local_table SELECT i, i FROM generate_series(0, 5) i; INSERT INTO citus_local_table_2 SELECT i, i FROM generate_series(0, 5) i; INSERT INTO postgres_local_table SELECT i, i FROM generate_series(0, 5) i; @@ -75,14 +75,14 @@ SELECT clear_and_init_test_tables(); -- join between citus local tables and reference tables would succeed SELECT count(*) FROM citus_local_table, reference_table WHERE citus_local_table.a = reference_table.a; -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table, citus_local_table_queries.reference_table_1509002 reference_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table, citus_local_table_queries.reference_table_1509003 reference_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) count --------------------------------------------------------------------- 6 (1 row) SELECT * FROM citus_local_table, reference_table WHERE citus_local_table.a = reference_table.a ORDER BY 1,2,3,4 FOR UPDATE; -NOTICE: executing the command locally: SELECT citus_local_table.a, citus_local_table.b, reference_table.a, reference_table.b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table, citus_local_table_queries.reference_table_1509002 reference_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) ORDER BY citus_local_table.a, citus_local_table.b, reference_table.a, reference_table.b FOR UPDATE OF citus_local_table FOR UPDATE OF reference_table +NOTICE: executing the command locally: SELECT citus_local_table.a, citus_local_table.b, reference_table.a, reference_table.b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table, citus_local_table_queries.reference_table_1509003 reference_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) ORDER BY citus_local_table.a, citus_local_table.b, reference_table.a, reference_table.b FOR UPDATE OF citus_local_table FOR UPDATE OF reference_table a | b | a | b --------------------------------------------------------------------- 0 | 0 | 0 | 0 @@ -97,7 +97,7 @@ NOTICE: executing the command locally: SELECT citus_local_table.a, citus_local_ WITH cte_1 AS (SELECT * FROM citus_local_table, reference_table WHERE citus_local_table.a = reference_table.a ORDER BY 1,2,3,4 FOR UPDATE) SELECT count(*) FROM cte_1; -NOTICE: executing the command locally: WITH cte_1 AS (SELECT citus_local_table.a, citus_local_table.b, reference_table.a, reference_table.b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table, citus_local_table_queries.reference_table_1509002 reference_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) ORDER BY citus_local_table.a, citus_local_table.b, reference_table.a, reference_table.b FOR UPDATE OF citus_local_table FOR UPDATE OF reference_table) SELECT count(*) AS count FROM cte_1 cte_1(a, b, a_1, b_1) +NOTICE: executing the command locally: WITH cte_1 AS (SELECT citus_local_table.a, citus_local_table.b, reference_table.a, reference_table.b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table, citus_local_table_queries.reference_table_1509003 reference_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) ORDER BY citus_local_table.a, citus_local_table.b, reference_table.a, reference_table.b FOR UPDATE OF citus_local_table FOR UPDATE OF reference_table) SELECT count(*) AS count FROM cte_1 cte_1(a, b, a_1, b_1) count --------------------------------------------------------------------- 6 @@ -112,7 +112,7 @@ cte_distributed_table AS (SELECT * FROM distributed_table) SELECT count(*) FROM cte_distributed_table, cte_citus_local_table, cte_postgres_local_table WHERE cte_citus_local_table.a = 1 AND cte_distributed_table.a = 1; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table count --------------------------------------------------------------------- 6 @@ -126,7 +126,7 @@ SELECT count(*) FROM ( SELECT * FROM (SELECT * FROM citus_local_table) as subquery_inner ) as subquery_top; -NOTICE: executing the command locally: SELECT count(*) AS count FROM (SELECT subquery_inner.a, subquery_inner.b FROM (SELECT citus_local_table.a, citus_local_table.b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table) subquery_inner) subquery_top +NOTICE: executing the command locally: SELECT count(*) AS count FROM (SELECT subquery_inner.a, subquery_inner.b FROM (SELECT citus_local_table.a, citus_local_table.b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table) subquery_inner) subquery_top count --------------------------------------------------------------------- 6 @@ -143,7 +143,7 @@ SELECT count(*) FROM ( SELECT * FROM (SELECT count(*) FROM citus_local_table, postgres_local_table) as subquery_inner ) as subquery_top; -NOTICE: executing the command locally: SELECT count(*) AS count FROM (SELECT subquery_inner.count FROM (SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table, citus_local_table_queries.postgres_local_table) subquery_inner) subquery_top +NOTICE: executing the command locally: SELECT count(*) AS count FROM (SELECT subquery_inner.count FROM (SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table, citus_local_table_queries.postgres_local_table) subquery_inner) subquery_top count --------------------------------------------------------------------- 1 @@ -154,7 +154,7 @@ SELECT count(*) FROM ( SELECT *, random() FROM (SELECT *, random() FROM citus_local_table, distributed_table) as subquery_inner ) as subquery_top; -NOTICE: executing the command locally: SELECT NULL::integer AS "dummy-1" FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE true +NOTICE: executing the command locally: SELECT NULL::integer AS "dummy-1" FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE true count --------------------------------------------------------------------- 36 @@ -167,7 +167,7 @@ SELECT count(*) FROM FROM ( WITH cte_1 AS (SELECT *, random() FROM citus_local_table, distributed_table) SELECT * FROM cte_1) as subquery_inner ) as subquery_top; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE true +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE true NOTICE: executing the command locally: SELECT count(*) AS count FROM (SELECT subquery_inner.a, subquery_inner.b, subquery_inner.a_1 AS a, subquery_inner.b_1 AS b, subquery_inner.random, random() AS random FROM (SELECT cte_1.a, cte_1.b, cte_1.a_1 AS a, cte_1.b_1 AS b, cte_1.random FROM (SELECT intermediate_result.a, intermediate_result.b, intermediate_result.a_1 AS a, intermediate_result.b_1 AS b, intermediate_result.random FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer, a_1 integer, b_1 integer, random double precision)) cte_1(a, b, a_1, b_1, random)) subquery_inner(a, b, a_1, b_1, random)) subquery_top(a, b, a_1, b_1, random, random_1) count --------------------------------------------------------------------- @@ -182,7 +182,7 @@ SELECT count(*) FROM WITH cte_1 AS (SELECT *, random() FROM citus_local_table), cte_2 AS (SELECT * FROM distributed_table) SELECT count(*) FROM cte_1, cte_2 ) as subquery_inner ) as subquery_top; -NOTICE: executing the command locally: SELECT a, b, random() AS random FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT a, b, random() AS random FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table NOTICE: executing the command locally: SELECT count(*) AS count FROM (SELECT subquery_inner.count, random() AS random FROM (SELECT intermediate_result.count FROM read_intermediate_result('XXX_2'::text, 'binary'::citus_copy_format) intermediate_result(count bigint)) subquery_inner) subquery_top count --------------------------------------------------------------------- @@ -199,42 +199,42 @@ SELECT clear_and_init_test_tables(); PREPARE citus_local_only AS SELECT count(*) FROM citus_local_table; -- execute 6 times, local tables without params EXECUTE citus_local_only; -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table count --------------------------------------------------------------------- 6 (1 row) EXECUTE citus_local_only; -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table count --------------------------------------------------------------------- 6 (1 row) EXECUTE citus_local_only; -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table count --------------------------------------------------------------------- 6 (1 row) EXECUTE citus_local_only; -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table count --------------------------------------------------------------------- 6 (1 row) EXECUTE citus_local_only; -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table count --------------------------------------------------------------------- 6 (1 row) EXECUTE citus_local_only; -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table count --------------------------------------------------------------------- 6 @@ -243,42 +243,42 @@ NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_loca -- execute 6 times, with param PREPARE citus_local_only_p(int) AS SELECT count(*) FROM citus_local_table WHERE a = $1; EXECUTE citus_local_only_p(1); -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) count --------------------------------------------------------------------- 1 (1 row) EXECUTE citus_local_only_p(1); -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) count --------------------------------------------------------------------- 1 (1 row) EXECUTE citus_local_only_p(1); -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) count --------------------------------------------------------------------- 1 (1 row) EXECUTE citus_local_only_p(1); -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) count --------------------------------------------------------------------- 1 (1 row) EXECUTE citus_local_only_p(1); -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) count --------------------------------------------------------------------- 1 (1 row) EXECUTE citus_local_only_p(1); -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) count --------------------------------------------------------------------- 1 @@ -287,14 +287,14 @@ NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_loca -- do not evalute the function -- show the logs EXECUTE citus_local_only_p(random()); -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) count --------------------------------------------------------------------- 1 (1 row) EXECUTE citus_local_only_p(random()); -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) $1) count --------------------------------------------------------------------- 1 @@ -310,49 +310,49 @@ PREPARE mixed_query(int, int, int) AS cte_mixes AS (SELECT * FROM cte_distributed_table, cte_citus_local_table, cte_postgres_local_table) SELECT count(*) FROM cte_mixes; EXECUTE mixed_query(1,2,3); -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) count --------------------------------------------------------------------- 1 (1 row) EXECUTE mixed_query(1,2,3); -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) count --------------------------------------------------------------------- 1 (1 row) EXECUTE mixed_query(1,2,3); -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) count --------------------------------------------------------------------- 1 (1 row) EXECUTE mixed_query(1,2,3); -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) count --------------------------------------------------------------------- 1 (1 row) EXECUTE mixed_query(1,2,3); -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) count --------------------------------------------------------------------- 1 (1 row) EXECUTE mixed_query(1,2,3); -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) count --------------------------------------------------------------------- 1 (1 row) EXECUTE mixed_query(1,2,3); -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) 1) count --------------------------------------------------------------------- 1 @@ -366,7 +366,7 @@ SELECT clear_and_init_test_tables(); -- anonymous columns WITH a AS (SELECT a, '' FROM citus_local_table GROUP BY a) SELECT a.a FROM a ORDER BY 1 LIMIT 5; -NOTICE: executing the command locally: SELECT a FROM (SELECT citus_local_table.a, ''::text FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table GROUP BY citus_local_table.a) a(a, "?column?") ORDER BY a LIMIT 5 +NOTICE: executing the command locally: SELECT a FROM (SELECT citus_local_table.a, ''::text FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table GROUP BY citus_local_table.a) a(a, "?column?") ORDER BY a LIMIT 5 a --------------------------------------------------------------------- 0 @@ -377,7 +377,7 @@ NOTICE: executing the command locally: SELECT a FROM (SELECT citus_local_table. (5 rows) WITH a AS (SELECT b, '' FROM citus_local_table WHERE a = 1) SELECT * FROM a, a b ORDER BY 1 LIMIT 5; -NOTICE: executing the command locally: WITH a AS (SELECT citus_local_table.b, ''::text FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) 1)) SELECT a.b, a."?column?", b.b, b."?column?" FROM a a(b, "?column?"), a b(b, "?column?") ORDER BY a.b LIMIT 5 +NOTICE: executing the command locally: WITH a AS (SELECT citus_local_table.b, ''::text FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) 1)) SELECT a.b, a."?column?", b.b, b."?column?" FROM a a(b, "?column?"), a b(b, "?column?") ORDER BY a.b LIMIT 5 b | ?column? | b | ?column? --------------------------------------------------------------------- 1 | | 1 | @@ -388,7 +388,7 @@ SELECT * FROM citus_local_table, postgres_local_table WHERE citus_local_table.a - postgres_local_table.a = 0 ORDER BY 1,2,3,4 LIMIT 10; -NOTICE: executing the command locally: SELECT citus_local_table.a, citus_local_table.b, postgres_local_table.a, postgres_local_table.b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table, citus_local_table_queries.postgres_local_table WHERE ((citus_local_table.a OPERATOR(pg_catalog.-) postgres_local_table.a) OPERATOR(pg_catalog.=) 0) ORDER BY citus_local_table.a, citus_local_table.b, postgres_local_table.a, postgres_local_table.b LIMIT 10 +NOTICE: executing the command locally: SELECT citus_local_table.a, citus_local_table.b, postgres_local_table.a, postgres_local_table.b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table, citus_local_table_queries.postgres_local_table WHERE ((citus_local_table.a OPERATOR(pg_catalog.-) postgres_local_table.a) OPERATOR(pg_catalog.=) 0) ORDER BY citus_local_table.a, citus_local_table.b, postgres_local_table.a, postgres_local_table.b LIMIT 10 a | b | a | b --------------------------------------------------------------------- 0 | 0 | 0 | 0 @@ -401,7 +401,7 @@ NOTICE: executing the command locally: SELECT citus_local_table.a, citus_local_ -- set operations should just work SELECT * FROM citus_local_table UNION SELECT * FROM postgres_local_table UNION SELECT * FROM distributed_table ORDER BY 1,2; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table NOTICE: executing the command locally: SELECT intermediate_result.a, intermediate_result.b FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer) UNION SELECT intermediate_result.a, intermediate_result.b FROM read_intermediate_result('XXX_2'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer) UNION SELECT intermediate_result.a, intermediate_result.b FROM read_intermediate_result('XXX_3'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer) ORDER BY 1, 2 a | b --------------------------------------------------------------------- @@ -414,7 +414,7 @@ NOTICE: executing the command locally: SELECT intermediate_result.a, intermedia (6 rows) (SELECT * FROM citus_local_table ORDER BY 1,2 LIMIT 5) INTERSECT (SELECT i, i FROM generate_series(0, 100) i) ORDER BY 1, 2; -NOTICE: executing the command locally: (SELECT citus_local_table.a, citus_local_table.b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table ORDER BY citus_local_table.a, citus_local_table.b LIMIT 5) INTERSECT SELECT i.i, i.i FROM generate_series(0, 100) i(i) ORDER BY 1, 2 +NOTICE: executing the command locally: (SELECT citus_local_table.a, citus_local_table.b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table ORDER BY citus_local_table.a, citus_local_table.b LIMIT 5) INTERSECT SELECT i.i, i.i FROM generate_series(0, 100) i(i) ORDER BY 1, 2 a | b --------------------------------------------------------------------- 0 | 0 @@ -426,28 +426,28 @@ NOTICE: executing the command locally: (SELECT citus_local_table.a, citus_local -- should just work as recursive planner kicks in SELECT count(*) FROM distributed_table WHERE a IN (SELECT a FROM citus_local_table); -NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table count --------------------------------------------------------------------- 6 (1 row) SELECT count(*) FROM citus_local_table WHERE a IN (SELECT a FROM distributed_table); -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer))) +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer))) count --------------------------------------------------------------------- 6 (1 row) SELECT count(*) FROM reference_table WHERE a IN (SELECT a FROM citus_local_table); -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.reference_table_1509002 reference_table WHERE (a OPERATOR(pg_catalog.=) ANY (SELECT citus_local_table.a FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table)) +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.reference_table_1509003 reference_table WHERE (a OPERATOR(pg_catalog.=) ANY (SELECT citus_local_table.a FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table)) count --------------------------------------------------------------------- 6 (1 row) SELECT count(*) FROM citus_local_table WHERE a IN (SELECT a FROM reference_table); -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) ANY (SELECT reference_table.a FROM citus_local_table_queries.reference_table_1509002 reference_table)) +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) ANY (SELECT reference_table.a FROM citus_local_table_queries.reference_table_1509003 reference_table)) count --------------------------------------------------------------------- 6 @@ -458,8 +458,8 @@ SELECT count(*) FROM citus_local_table WHERE a IN (SELECT a FROM distributed_table WHERE a IN (SELECT b FROM citus_local_table WHERE b IN (SELECT b FROM postgres_local_table))); -NOTICE: executing the command locally: SELECT b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (b OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.b FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(b integer))) -NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.a FROM read_intermediate_result('XXX_3'::text, 'binary'::citus_copy_format) intermediate_result(a integer))) +NOTICE: executing the command locally: SELECT b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (b OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.b FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(b integer))) +NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.a FROM read_intermediate_result('XXX_3'::text, 'binary'::citus_copy_format) intermediate_result(a integer))) count --------------------------------------------------------------------- 6 @@ -467,7 +467,7 @@ NOTICE: executing the command locally: SELECT count(*) AS count FROM citus_loca -- local outer joins SELECT count(*) FROM citus_local_table LEFT JOIN reference_table ON (true); -NOTICE: executing the command locally: SELECT count(*) AS count FROM (citus_local_table_queries.citus_local_table_1509000 citus_local_table LEFT JOIN citus_local_table_queries.reference_table_1509002 reference_table ON (true)) +NOTICE: executing the command locally: SELECT count(*) AS count FROM (citus_local_table_queries.citus_local_table_1509001 citus_local_table LEFT JOIN citus_local_table_queries.reference_table_1509003 reference_table ON (true)) count --------------------------------------------------------------------- 36 @@ -477,7 +477,7 @@ SELECT count(*) FROM reference_table LEFT JOIN citus_local_table ON (true) LEFT JOIN postgres_local_table ON (true) LEFT JOIN reference_table r2 ON (true); -NOTICE: executing the command locally: SELECT count(*) AS count FROM (((citus_local_table_queries.reference_table_1509002 reference_table LEFT JOIN citus_local_table_queries.citus_local_table_1509000 citus_local_table ON (true)) LEFT JOIN citus_local_table_queries.postgres_local_table ON (true)) LEFT JOIN citus_local_table_queries.reference_table_1509002 r2 ON (true)) +NOTICE: executing the command locally: SELECT count(*) AS count FROM (((citus_local_table_queries.reference_table_1509003 reference_table LEFT JOIN citus_local_table_queries.citus_local_table_1509001 citus_local_table ON (true)) LEFT JOIN citus_local_table_queries.postgres_local_table ON (true)) LEFT JOIN citus_local_table_queries.reference_table_1509003 r2 ON (true)) count --------------------------------------------------------------------- 1296 @@ -500,7 +500,7 @@ ORDER BY 1, 2 LIMIT 1; -NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (b OPERATOR(pg_catalog.=) 1) +NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (b OPERATOR(pg_catalog.=) 1) a | b --------------------------------------------------------------------- 1 | 1 @@ -519,7 +519,7 @@ ORDER BY 1 ,2 LIMIT 1; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (b OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer))) ORDER BY a, b LIMIT 1 +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (b OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer))) ORDER BY a, b LIMIT 1 a | b --------------------------------------------------------------------- 1 | 1 @@ -527,7 +527,7 @@ NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queri -- join between citus local tables and distributed tables would fail SELECT count(*) FROM citus_local_table, distributed_table; -NOTICE: executing the command locally: SELECT NULL::integer AS "dummy-1" FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE true +NOTICE: executing the command locally: SELECT NULL::integer AS "dummy-1" FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE true count --------------------------------------------------------------------- 36 @@ -539,7 +539,7 @@ ERROR: could not run distributed query with FOR UPDATE/SHARE commands SELECT count(citus_local_table.b), count(postgres_local_table.a) FROM citus_local_table, postgres_local_table WHERE citus_local_table.a = postgres_local_table.b; -NOTICE: executing the command locally: SELECT count(citus_local_table.b) AS count, count(postgres_local_table.a) AS count FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table, citus_local_table_queries.postgres_local_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) postgres_local_table.b) +NOTICE: executing the command locally: SELECT count(citus_local_table.b) AS count, count(postgres_local_table.a) AS count FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table, citus_local_table_queries.postgres_local_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) postgres_local_table.b) count | count --------------------------------------------------------------------- 6 | 6 @@ -547,7 +547,7 @@ NOTICE: executing the command locally: SELECT count(citus_local_table.b) AS cou -- select for update is just OK SELECT * FROM citus_local_table ORDER BY 1,2 FOR UPDATE; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table ORDER BY a, b FOR UPDATE OF citus_local_table +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table ORDER BY a, b FOR UPDATE OF citus_local_table a | b --------------------------------------------------------------------- 0 | 0 @@ -570,32 +570,32 @@ SELECT clear_and_init_test_tables(); INSERT INTO citus_local_table SELECT * from reference_table; -NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509000 AS citus_table_alias (a, b) SELECT a, b FROM citus_local_table_queries.reference_table_1509002 reference_table +NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509001 AS citus_table_alias (a, b) SELECT a, b FROM citus_local_table_queries.reference_table_1509003 reference_table INSERT INTO reference_table SELECT * from citus_local_table; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table NOTICE: executing the copy locally for shard xxxxx INSERT INTO citus_local_table SELECT * from distributed_table; NOTICE: executing the copy locally for shard xxxxx INSERT INTO distributed_table SELECT * from citus_local_table; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table INSERT INTO citus_local_table SELECT * from citus_local_table_2; -NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509000 AS citus_table_alias (a, b) SELECT a, b FROM citus_local_table_queries.citus_local_table_2_1509001 citus_local_table_2 +NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509001 AS citus_table_alias (a, b) SELECT a, b FROM citus_local_table_queries.citus_local_table_2_1509002 citus_local_table_2 INSERT INTO citus_local_table SELECT * from citus_local_table_2 ORDER BY 1,2 LIMIT 10; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_2_1509001 citus_local_table_2 ORDER BY a, b LIMIT 10 +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_2_1509002 citus_local_table_2 ORDER BY a, b LIMIT 10 NOTICE: executing the copy locally for shard xxxxx INSERT INTO citus_local_table SELECT * from postgres_local_table; NOTICE: executing the copy locally for shard xxxxx INSERT INTO postgres_local_table SELECT * from citus_local_table; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table -- INSERT SELECT with local joins are OK SELECT clear_and_init_test_tables(); clear_and_init_test_tables @@ -606,16 +606,16 @@ SELECT clear_and_init_test_tables(); INSERT INTO citus_local_table SELECT reference_table.* FROM reference_table JOIN citus_local_table ON (true); -NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509000 AS citus_table_alias (a, b) SELECT reference_table.a, reference_table.b FROM (citus_local_table_queries.reference_table_1509002 reference_table JOIN citus_local_table_queries.citus_local_table_1509000 citus_local_table ON (true)) +NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509001 AS citus_table_alias (a, b) SELECT reference_table.a, reference_table.b FROM (citus_local_table_queries.reference_table_1509003 reference_table JOIN citus_local_table_queries.citus_local_table_1509001 citus_local_table ON (true)) INSERT INTO reference_table SELECT reference_table.* FROM reference_table JOIN citus_local_table ON (true); -NOTICE: executing the command locally: SELECT reference_table.a, reference_table.b FROM (citus_local_table_queries.reference_table_1509002 reference_table JOIN citus_local_table_queries.citus_local_table_1509000 citus_local_table ON (true)) +NOTICE: executing the command locally: SELECT reference_table.a, reference_table.b FROM (citus_local_table_queries.reference_table_1509003 reference_table JOIN citus_local_table_queries.citus_local_table_1509001 citus_local_table ON (true)) NOTICE: executing the copy locally for shard xxxxx INSERT INTO reference_table SELECT reference_table.* FROM reference_table, postgres_local_table JOIN citus_local_table ON (true); -NOTICE: executing the command locally: SELECT reference_table.a, reference_table.b FROM citus_local_table_queries.reference_table_1509002 reference_table, (citus_local_table_queries.postgres_local_table JOIN citus_local_table_queries.citus_local_table_1509000 citus_local_table ON (true)) +NOTICE: executing the command locally: SELECT reference_table.a, reference_table.b FROM citus_local_table_queries.reference_table_1509003 reference_table, (citus_local_table_queries.postgres_local_table JOIN citus_local_table_queries.citus_local_table_1509001 citus_local_table ON (true)) NOTICE: executing the copy locally for shard xxxxx SELECT clear_and_init_test_tables(); clear_and_init_test_tables @@ -626,15 +626,15 @@ SELECT clear_and_init_test_tables(); INSERT INTO distributed_table SELECT reference_table.* FROM reference_table JOIN citus_local_table ON (true); -NOTICE: executing the command locally: SELECT reference_table.a, reference_table.b FROM (citus_local_table_queries.reference_table_1509002 reference_table JOIN citus_local_table_queries.citus_local_table_1509000 citus_local_table ON (true)) +NOTICE: executing the command locally: SELECT reference_table.a, reference_table.b FROM (citus_local_table_queries.reference_table_1509003 reference_table JOIN citus_local_table_queries.citus_local_table_1509001 citus_local_table ON (true)) INSERT INTO distributed_table SELECT reference_table.* FROM reference_table, postgres_local_table JOIN citus_local_table ON (true); -NOTICE: executing the command locally: SELECT reference_table.a, reference_table.b FROM citus_local_table_queries.reference_table_1509002 reference_table, (citus_local_table_queries.postgres_local_table JOIN citus_local_table_queries.citus_local_table_1509000 citus_local_table ON (true)) +NOTICE: executing the command locally: SELECT reference_table.a, reference_table.b FROM citus_local_table_queries.reference_table_1509003 reference_table, (citus_local_table_queries.postgres_local_table JOIN citus_local_table_queries.citus_local_table_1509001 citus_local_table ON (true)) INSERT INTO postgres_local_table SELECT reference_table.* FROM reference_table JOIN citus_local_table ON (true); -NOTICE: executing the command locally: SELECT reference_table.a, reference_table.b FROM (citus_local_table_queries.reference_table_1509002 reference_table JOIN citus_local_table_queries.citus_local_table_1509000 citus_local_table ON (true)) +NOTICE: executing the command locally: SELECT reference_table.a, reference_table.b FROM (citus_local_table_queries.reference_table_1509003 reference_table JOIN citus_local_table_queries.citus_local_table_1509001 citus_local_table ON (true)) -- INSERT SELECT that joins reference and distributed tables is also OK SELECT clear_and_init_test_tables(); clear_and_init_test_tables @@ -654,17 +654,17 @@ NOTICE: executing the copy locally for shard xxxxx INSERT INTO citus_local_table SELECT distributed_table.* FROM distributed_table JOIN citus_local_table ON (true); -NOTICE: executing the command locally: SELECT NULL::integer AS "dummy-1" FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE true +NOTICE: executing the command locally: SELECT NULL::integer AS "dummy-1" FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE true NOTICE: executing the copy locally for shard xxxxx -- .. but when wrapped into a CTE, join works fine INSERT INTO citus_local_table SELECT distributed_table.* FROM distributed_table JOIN (WITH cte AS (SELECT * FROM citus_local_table) SELECT * FROM cte) as foo ON (true); -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table NOTICE: executing the copy locally for shard xxxxx -- multi row insert is OK INSERT INTO citus_local_table VALUES (1, 2), (3, 4); -NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509000 AS citus_table_alias (a, b) VALUES (1,2), (3,4) +NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509001 AS citus_table_alias (a, b) VALUES (1,2), (3,4) --------------------------------------------------------------------- ----- DELETE / UPDATE ----- --------------------------------------------------------------------- @@ -679,83 +679,83 @@ SELECT clear_and_init_test_tables(); DELETE FROM citus_local_table USING postgres_local_table WHERE citus_local_table.b = postgres_local_table.b; -NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table USING citus_local_table_queries.postgres_local_table WHERE (citus_local_table.b OPERATOR(pg_catalog.=) postgres_local_table.b) +NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table USING citus_local_table_queries.postgres_local_table WHERE (citus_local_table.b OPERATOR(pg_catalog.=) postgres_local_table.b) UPDATE citus_local_table SET b = 5 FROM postgres_local_table WHERE citus_local_table.a = 3 AND citus_local_table.b = postgres_local_table.b; -NOTICE: executing the command locally: UPDATE citus_local_table_queries.citus_local_table_1509000 citus_local_table SET b = 5 FROM citus_local_table_queries.postgres_local_table WHERE ((citus_local_table.a OPERATOR(pg_catalog.=) 3) AND (citus_local_table.b OPERATOR(pg_catalog.=) postgres_local_table.b)) +NOTICE: executing the command locally: UPDATE citus_local_table_queries.citus_local_table_1509001 citus_local_table SET b = 5 FROM citus_local_table_queries.postgres_local_table WHERE ((citus_local_table.a OPERATOR(pg_catalog.=) 3) AND (citus_local_table.b OPERATOR(pg_catalog.=) postgres_local_table.b)) DELETE FROM postgres_local_table USING citus_local_table WHERE citus_local_table.b = postgres_local_table.b; -NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.postgres_local_table USING citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (citus_local_table.b OPERATOR(pg_catalog.=) postgres_local_table.b) +NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.postgres_local_table USING citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (citus_local_table.b OPERATOR(pg_catalog.=) postgres_local_table.b) UPDATE postgres_local_table SET b = 5 FROM citus_local_table WHERE citus_local_table.a = 3 AND citus_local_table.b = postgres_local_table.b; -NOTICE: executing the command locally: UPDATE citus_local_table_queries.postgres_local_table SET b = 5 FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE ((citus_local_table.a OPERATOR(pg_catalog.=) 3) AND (citus_local_table.b OPERATOR(pg_catalog.=) postgres_local_table.b)) +NOTICE: executing the command locally: UPDATE citus_local_table_queries.postgres_local_table SET b = 5 FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE ((citus_local_table.a OPERATOR(pg_catalog.=) 3) AND (citus_local_table.b OPERATOR(pg_catalog.=) postgres_local_table.b)) -- no direct joins supported UPDATE distributed_table SET b = 6 FROM citus_local_table WHERE citus_local_table.a = distributed_table.a; -NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE true +NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE true UPDATE reference_table SET b = 6 FROM citus_local_table WHERE citus_local_table.a = reference_table.a; -NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE true -NOTICE: executing the command locally: UPDATE citus_local_table_queries.reference_table_1509002 reference_table SET b = 6 FROM (SELECT citus_local_table_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) citus_local_table_1) citus_local_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) +NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE true +NOTICE: executing the command locally: UPDATE citus_local_table_queries.reference_table_1509003 reference_table SET b = 6 FROM (SELECT citus_local_table_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) citus_local_table_1) citus_local_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) -- should not work, add HINT use CTEs UPDATE citus_local_table SET b = 6 FROM distributed_table WHERE citus_local_table.a = distributed_table.a; -NOTICE: executing the command locally: UPDATE citus_local_table_queries.citus_local_table_1509000 citus_local_table SET b = 6 FROM (SELECT distributed_table_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) distributed_table_1) distributed_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) distributed_table.a) +NOTICE: executing the command locally: UPDATE citus_local_table_queries.citus_local_table_1509001 citus_local_table SET b = 6 FROM (SELECT distributed_table_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) distributed_table_1) distributed_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) distributed_table.a) -- should work, add HINT use CTEs UPDATE citus_local_table SET b = 6 FROM reference_table WHERE citus_local_table.a = reference_table.a; -NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.reference_table_1509002 reference_table WHERE true -NOTICE: executing the command locally: UPDATE citus_local_table_queries.citus_local_table_1509000 citus_local_table SET b = 6 FROM (SELECT reference_table_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) reference_table_1) reference_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) +NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.reference_table_1509003 reference_table WHERE true +NOTICE: executing the command locally: UPDATE citus_local_table_queries.citus_local_table_1509001 citus_local_table SET b = 6 FROM (SELECT reference_table_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) reference_table_1) reference_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) -- should not work, add HINT use CTEs DELETE FROM distributed_table USING citus_local_table WHERE citus_local_table.a = distributed_table.a; -NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE true +NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE true -- should not work, add HINT use CTEs DELETE FROM citus_local_table USING distributed_table WHERE citus_local_table.a = distributed_table.a; -NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table USING (SELECT distributed_table_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) distributed_table_1) distributed_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) distributed_table.a) +NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table USING (SELECT distributed_table_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) distributed_table_1) distributed_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) distributed_table.a) DELETE FROM reference_table USING citus_local_table WHERE citus_local_table.a = reference_table.a; -NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE true -NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.reference_table_1509002 reference_table USING (SELECT citus_local_table_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) citus_local_table_1) citus_local_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) +NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE true +NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.reference_table_1509003 reference_table USING (SELECT citus_local_table_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) citus_local_table_1) citus_local_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) -- should work, add HINT use CTEs DELETE FROM citus_local_table USING reference_table WHERE citus_local_table.a = reference_table.a; -NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.reference_table_1509002 reference_table WHERE true -NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table USING (SELECT reference_table_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) reference_table_1) reference_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) +NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.reference_table_1509003 reference_table WHERE true +NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table USING (SELECT reference_table_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) reference_table_1) reference_table WHERE (citus_local_table.a OPERATOR(pg_catalog.=) reference_table.a) -- just works DELETE FROM citus_local_table WHERE citus_local_table.a IN (SELECT a FROM distributed_table); -NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer))) +NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer))) -- just works DELETE FROM citus_local_table WHERE citus_local_table.a IN (SELECT a FROM reference_table); -NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.reference_table_1509002 reference_table -NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE (a OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer))) +NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.reference_table_1509003 reference_table +NOTICE: executing the command locally: DELETE FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE (a OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer))) -- just works WITH distributed_table_cte AS (SELECT * FROM distributed_table) UPDATE citus_local_table SET b = 6 FROM distributed_table_cte WHERE citus_local_table.a = distributed_table_cte.a; -NOTICE: executing the command locally: UPDATE citus_local_table_queries.citus_local_table_1509000 citus_local_table SET b = 6 FROM (SELECT intermediate_result.a, intermediate_result.b FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer)) distributed_table_cte WHERE (citus_local_table.a OPERATOR(pg_catalog.=) distributed_table_cte.a) +NOTICE: executing the command locally: UPDATE citus_local_table_queries.citus_local_table_1509001 citus_local_table SET b = 6 FROM (SELECT intermediate_result.a, intermediate_result.b FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer)) distributed_table_cte WHERE (citus_local_table.a OPERATOR(pg_catalog.=) distributed_table_cte.a) SET citus.log_local_commands to off; -- just works WITH reference_table_cte AS (SELECT * FROM reference_table) @@ -772,7 +772,7 @@ SELECT count(*) FROM citus_local_table JOIN reference_table USING (a); -NOTICE: executing the command locally: SELECT count(*) AS count FROM (citus_local_table_queries.citus_local_table_1509000 citus_local_table(a, b) JOIN citus_local_table_queries.reference_table_1509002 reference_table(a, b) USING (a)) +NOTICE: executing the command locally: SELECT count(*) AS count FROM (citus_local_table_queries.citus_local_table_1509001 citus_local_table(a, b) JOIN citus_local_table_queries.reference_table_1509003 reference_table(a, b) USING (a)) -- ok SELECT count(*) FROM mat_view_4; count @@ -795,8 +795,8 @@ JOIN citus_local_table_2 USING (a) JOIN distributed_table USING (a); -- should fail as view contains direct local dist join SELECT count(*) FROM view_2; -NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table WHERE true -NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_2_1509001 citus_local_table_2 WHERE true +NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table WHERE true +NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_2_1509002 citus_local_table_2 WHERE true NOTICE: executing the command locally: SELECT count(*) AS count FROM (SELECT intermediate_result.count FROM read_intermediate_result('XXX_3'::text, 'binary'::citus_copy_format) intermediate_result(count bigint)) view_2 count --------------------------------------------------------------------- @@ -810,7 +810,7 @@ JOIN reference_table USING (a); -- ok SELECT count(*) FROM view_3; -NOTICE: executing the command locally: SELECT count(*) AS count FROM (SELECT count(*) AS count FROM (citus_local_table_queries.citus_local_table_2_1509001 citus_local_table_2(a, b) JOIN citus_local_table_queries.reference_table_1509002 reference_table(a, b) USING (a))) view_3 +NOTICE: executing the command locally: SELECT count(*) AS count FROM (SELECT count(*) AS count FROM (citus_local_table_queries.citus_local_table_2_1509002 citus_local_table_2(a, b) JOIN citus_local_table_queries.reference_table_1509003 reference_table(a, b) USING (a))) view_3 count --------------------------------------------------------------------- 1 @@ -818,8 +818,8 @@ NOTICE: executing the command locally: SELECT count(*) AS count FROM (SELECT co -- view treated as subquery, so should work SELECT count(*) FROM view_3, distributed_table; -NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_2_1509001 citus_local_table_2 WHERE true -NOTICE: executing the command locally: SELECT count(*) AS count FROM ((SELECT citus_local_table_2_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) citus_local_table_2_1) citus_local_table_2 JOIN citus_local_table_queries.reference_table_1509002 reference_table(a, b) USING (a)) +NOTICE: executing the command locally: SELECT a FROM citus_local_table_queries.citus_local_table_2_1509002 citus_local_table_2 WHERE true +NOTICE: executing the command locally: SELECT count(*) AS count FROM ((SELECT citus_local_table_2_1.a, NULL::integer AS b FROM (SELECT intermediate_result.a FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer)) citus_local_table_2_1) citus_local_table_2 JOIN citus_local_table_queries.reference_table_1509003 reference_table(a, b) USING (a)) count --------------------------------------------------------------------- 6 @@ -845,10 +845,10 @@ JOIN (SELECT count(*) as a, count(*) as b USING (a)) subquery7132 USING (b)) subquery7294 USING (a); -NOTICE: executing the command locally: SELECT count(*) AS a, count(*) AS b FROM (citus_local_table_queries.reference_table_1509002 reference_table(a, b) JOIN (SELECT count(*) AS a, count(*) AS b FROM (citus_local_table_queries.citus_local_table_2_1509001 citus_local_table_2(a, b) JOIN (SELECT count(*) AS a, count(*) AS b FROM (citus_local_table_queries.postgres_local_table JOIN (SELECT count(*) AS a, count(*) AS b FROM citus_local_table_queries.reference_table_1509002 table_4677) subquery5108 USING (a))) subquery7132 USING (b))) subquery7294 USING (a)) +NOTICE: executing the command locally: SELECT count(*) AS a, count(*) AS b FROM (citus_local_table_queries.reference_table_1509003 reference_table(a, b) JOIN (SELECT count(*) AS a, count(*) AS b FROM (citus_local_table_queries.citus_local_table_2_1509002 citus_local_table_2(a, b) JOIN (SELECT count(*) AS a, count(*) AS b FROM (citus_local_table_queries.postgres_local_table JOIN (SELECT count(*) AS a, count(*) AS b FROM citus_local_table_queries.reference_table_1509003 table_4677) subquery5108 USING (a))) subquery7132 USING (b))) subquery7294 USING (a)) a | b --------------------------------------------------------------------- - 0 | 0 + 1 | 1 (1 row) -- direct join inside CTE not supported @@ -857,7 +857,7 @@ UPDATE citus_local_table lt SET a = mt.a FROM distributed_table mt WHERE mt.b = lt.b RETURNING lt.b, lt.a ) SELECT * FROM cte JOIN distributed_table mt ON mt.b = cte.b ORDER BY 1,2,3,4; -NOTICE: executing the command locally: UPDATE citus_local_table_queries.citus_local_table_1509000 lt SET a = mt.a FROM (SELECT mt_1.a, mt_1.b FROM (SELECT intermediate_result.a, intermediate_result.b FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer)) mt_1) mt WHERE (mt.b OPERATOR(pg_catalog.=) lt.b) RETURNING lt.b, lt.a +NOTICE: executing the command locally: UPDATE citus_local_table_queries.citus_local_table_1509001 lt SET a = mt.a FROM (SELECT mt_1.a, mt_1.b FROM (SELECT intermediate_result.a, intermediate_result.b FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(a integer, b integer)) mt_1) mt WHERE (mt.b OPERATOR(pg_catalog.=) lt.b) RETURNING lt.b, lt.a b | a | a | b --------------------------------------------------------------------- 0 | 0 | 0 | 0 @@ -875,14 +875,14 @@ FROM (SELECT avg(distributed_table.b) as avg_b FROM distributed_table) as foo WHERE foo.avg_b = citus_local_table.b; -NOTICE: executing the command locally: UPDATE citus_local_table_queries.citus_local_table_1509000 citus_local_table SET a = 5 FROM (SELECT intermediate_result.avg_b FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(avg_b numeric)) foo WHERE (foo.avg_b OPERATOR(pg_catalog.=) (citus_local_table.b)::numeric) +NOTICE: executing the command locally: UPDATE citus_local_table_queries.citus_local_table_1509001 citus_local_table SET a = 5 FROM (SELECT intermediate_result.avg_b FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(avg_b numeric)) foo WHERE (foo.avg_b OPERATOR(pg_catalog.=) (citus_local_table.b)::numeric) -- should work UPDATE distributed_table SET b = avg_a FROM (SELECT avg(citus_local_table.a) as avg_a FROM citus_local_table) as foo WHERE foo.avg_a = distributed_table.a RETURNING distributed_table.*; -NOTICE: executing the command locally: SELECT avg(a) AS avg_a FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT avg(a) AS avg_a FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table a | b --------------------------------------------------------------------- (0 rows) @@ -918,7 +918,7 @@ LIMIT 10; -> Limit -> Sort Sort Key: distributed_table.* - -> Seq Scan on distributed_table_1509003 distributed_table + -> Seq Scan on distributed_table_1509004 distributed_table (14 rows) -- show that we do not pull to coordinator @@ -932,8 +932,8 @@ SELECT * FROM citus_local_table; Tasks Shown: All -> Task Node: host=localhost port=xxxxx dbname=regression - -> Insert on citus_local_table_1509000 citus_table_alias - -> Seq Scan on citus_local_table_1509000 citus_local_table + -> Insert on citus_local_table_1509001 citus_table_alias + -> Seq Scan on citus_local_table_1509001 citus_local_table (7 rows) EXPLAIN (COSTS FALSE) @@ -946,8 +946,8 @@ SELECT reference_table.* FROM reference_table; Tasks Shown: All -> Task Node: host=localhost port=xxxxx dbname=regression - -> Insert on citus_local_table_1509000 citus_table_alias - -> Seq Scan on reference_table_1509002 reference_table + -> Insert on citus_local_table_1509001 citus_table_alias + -> Seq Scan on reference_table_1509003 reference_table (7 rows) EXPLAIN (COSTS FALSE) @@ -963,7 +963,7 @@ SELECT reference_table.* FROM reference_table, postgres_local_table; -> Task Node: host=localhost port=xxxxx dbname=regression -> Nested Loop - -> Seq Scan on reference_table_1509002 reference_table + -> Seq Scan on reference_table_1509003 reference_table -> Materialize -> Seq Scan on postgres_local_table (11 rows) @@ -982,9 +982,9 @@ SELECT reference_table.* FROM reference_table, distributed_table; -> Task Node: host=localhost port=xxxxx dbname=regression -> Nested Loop - -> Seq Scan on distributed_table_1509003 distributed_table + -> Seq Scan on distributed_table_1509004 distributed_table -> Materialize - -> Seq Scan on reference_table_1509002 reference_table + -> Seq Scan on reference_table_1509003 reference_table (11 rows) -- truncate tables & add unique constraints to be able to define foreign keys @@ -992,21 +992,21 @@ TRUNCATE reference_table, citus_local_table, distributed_table; NOTICE: executing the command locally: TRUNCATE TABLE citus_local_table_queries.reference_table_xxxxx CASCADE NOTICE: executing the command locally: TRUNCATE TABLE citus_local_table_queries.citus_local_table_xxxxx CASCADE ALTER TABLE reference_table ADD CONSTRAINT pkey_ref PRIMARY KEY (a); -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1509002, 'citus_local_table_queries', 'ALTER TABLE reference_table ADD CONSTRAINT pkey_ref PRIMARY KEY (a);') +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1509003, 'citus_local_table_queries', 'ALTER TABLE reference_table ADD CONSTRAINT pkey_ref PRIMARY KEY (a);') ALTER TABLE citus_local_table ADD CONSTRAINT pkey_c PRIMARY KEY (a); -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1509000, 'citus_local_table_queries', 'ALTER TABLE citus_local_table ADD CONSTRAINT pkey_c PRIMARY KEY (a);') +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1509001, 'citus_local_table_queries', 'ALTER TABLE citus_local_table ADD CONSTRAINT pkey_c PRIMARY KEY (a);') -- define a foreign key chain distributed table -> reference table -> citus local table -- to test sequential execution ALTER TABLE distributed_table ADD CONSTRAINT fkey_dist_to_ref FOREIGN KEY(a) REFERENCES reference_table(a) ON DELETE RESTRICT; ALTER TABLE reference_table ADD CONSTRAINT fkey_ref_to_local FOREIGN KEY(a) REFERENCES citus_local_table(a) ON DELETE RESTRICT; -NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1509002, 'citus_local_table_queries', 1509000, 'citus_local_table_queries', 'ALTER TABLE reference_table ADD CONSTRAINT fkey_ref_to_local FOREIGN KEY(a) REFERENCES citus_local_table(a) ON DELETE RESTRICT;') +NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1509003, 'citus_local_table_queries', 1509001, 'citus_local_table_queries', 'ALTER TABLE reference_table ADD CONSTRAINT fkey_ref_to_local FOREIGN KEY(a) REFERENCES citus_local_table(a) ON DELETE RESTRICT;') INSERT INTO citus_local_table VALUES (1); -NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509000 (a) VALUES (1) +NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509001 (a) VALUES (1) INSERT INTO reference_table VALUES (1); -NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.reference_table_1509002 (a) VALUES (1) +NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.reference_table_1509003 (a) VALUES (1) BEGIN; INSERT INTO citus_local_table VALUES (1) ON CONFLICT (a) DO NOTHING; -NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509000 AS citus_table_alias (a) VALUES (1) ON CONFLICT(a) DO NOTHING +NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509001 AS citus_table_alias (a) VALUES (1) ON CONFLICT(a) DO NOTHING INSERT INTO distributed_table VALUES (1); -- should show sequential as first inserting into citus local table -- would force the xact block to use sequential execution @@ -1042,7 +1042,7 @@ ROLLBACK; ALTER TABLE distributed_table DROP CONSTRAINT fkey_dist_to_ref; BEGIN; INSERT INTO citus_local_table VALUES (1) ON CONFLICT (a) DO NOTHING; -NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509000 AS citus_table_alias (a) VALUES (1) ON CONFLICT(a) DO NOTHING +NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509001 AS citus_table_alias (a) VALUES (1) ON CONFLICT(a) DO NOTHING show citus.multi_shard_modify_mode; citus.multi_shard_modify_mode --------------------------------------------------------------------- @@ -1052,9 +1052,9 @@ NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.ci ROLLBACK; -- remove uniqueness constraint and dependent foreign key constraint for next tests ALTER TABLE reference_table DROP CONSTRAINT fkey_ref_to_local; -NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1509002, 'citus_local_table_queries', 1509000, 'citus_local_table_queries', 'ALTER TABLE reference_table DROP CONSTRAINT fkey_ref_to_local;') +NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1509003, 'citus_local_table_queries', 1509001, 'citus_local_table_queries', 'ALTER TABLE reference_table DROP CONSTRAINT fkey_ref_to_local;') ALTER TABLE citus_local_table DROP CONSTRAINT pkey_c; -NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1509000, 'citus_local_table_queries', 'ALTER TABLE citus_local_table DROP CONSTRAINT pkey_c;') +NOTICE: executing the command locally: SELECT worker_apply_shard_ddl_command (1509001, 'citus_local_table_queries', 'ALTER TABLE citus_local_table DROP CONSTRAINT pkey_c;') COPY citus_local_table(a) FROM PROGRAM 'seq 1'; -- should use local execution BEGIN; @@ -1069,7 +1069,7 @@ COPY citus_local_table TO STDOUT; 1 \N 1 \N COPY (SELECT * FROM citus_local_table) TO STDOUT; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table 1 \N 1 \N 1 \N @@ -1083,7 +1083,7 @@ BEGIN; COMMIT; BEGIN; COPY (SELECT * FROM citus_local_table) TO STDOUT; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table 1 \N 1 \N 1 \N @@ -1095,13 +1095,13 @@ NOTICE: executing the command locally: TRUNCATE TABLE citus_local_table_queries NOTICE: executing the command locally: TRUNCATE TABLE citus_local_table_queries.reference_table_xxxxx CASCADE BEGIN; INSERT INTO citus_local_table VALUES (1), (2); -NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509000 AS citus_table_alias (a) VALUES (1), (2) +NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509001 AS citus_table_alias (a) VALUES (1), (2) SAVEPOINT sp1; INSERT INTO citus_local_table VALUES (3), (4); -NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509000 AS citus_table_alias (a) VALUES (3), (4) +NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509001 AS citus_table_alias (a) VALUES (3), (4) ROLLBACK TO SAVEPOINT sp1; SELECT * FROM citus_local_table ORDER BY 1,2; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table ORDER BY a, b +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table ORDER BY a, b a | b --------------------------------------------------------------------- 1 | @@ -1109,12 +1109,12 @@ NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queri (2 rows) SAVEPOINT sp2; - INSERT INTO citus_local_table VALUES (5), (6); -NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509000 AS citus_table_alias (a) VALUES (5), (6) - INSERT INTO distributed_table VALUES (5), (6); + INSERT INTO citus_local_table VALUES (3), (4); +NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509001 AS citus_table_alias (a) VALUES (3), (4) + INSERT INTO distributed_table VALUES (3), (4); ROLLBACK TO SAVEPOINT sp2; SELECT * FROM citus_local_table ORDER BY 1,2; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table ORDER BY a, b +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table ORDER BY a, b a | b --------------------------------------------------------------------- 1 | @@ -1127,13 +1127,13 @@ NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queri (0 rows) SAVEPOINT sp3; - INSERT INTO citus_local_table VALUES (7), (8); -NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509000 AS citus_table_alias (a) VALUES (7), (8) - INSERT INTO reference_table VALUES (7), (8); -NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.reference_table_1509002 AS citus_table_alias (a) VALUES (7), (8) + INSERT INTO citus_local_table VALUES (3), (2); +NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.citus_local_table_1509001 AS citus_table_alias (a) VALUES (3), (2) + INSERT INTO reference_table VALUES (3), (2); +NOTICE: executing the command locally: INSERT INTO citus_local_table_queries.reference_table_1509003 AS citus_table_alias (a) VALUES (3), (2) ROLLBACK TO SAVEPOINT sp3; SELECT * FROM citus_local_table ORDER BY 1,2; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509000 citus_local_table ORDER BY a, b +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.citus_local_table_1509001 citus_local_table ORDER BY a, b a | b --------------------------------------------------------------------- 1 | @@ -1141,7 +1141,7 @@ NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queri (2 rows) SELECT * FROM reference_table ORDER BY 1,2; -NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.reference_table_1509002 reference_table ORDER BY a, b +NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queries.reference_table_1509003 reference_table ORDER BY a, b a | b --------------------------------------------------------------------- (0 rows) @@ -1149,4 +1149,4 @@ NOTICE: executing the command locally: SELECT a, b FROM citus_local_table_queri COMMIT; -- cleanup at exit DROP SCHEMA citus_local_table_queries CASCADE; -NOTICE: drop cascades to 12 other objects +NOTICE: drop cascades to 14 other objects diff --git a/src/test/regress/expected/citus_local_tables_queries_mx.out b/src/test/regress/expected/citus_local_tables_queries_mx.out index ce61c7fdb..6bd2dc227 100644 --- a/src/test/regress/expected/citus_local_tables_queries_mx.out +++ b/src/test/regress/expected/citus_local_tables_queries_mx.out @@ -22,20 +22,19 @@ SELECT start_metadata_sync_to_node('localhost', :worker_1_port); (1 row) SET citus.replication_model TO streaming; +CREATE TABLE dummy_reference_table(a int unique, b int); +SELECT create_reference_table('dummy_reference_table'); + create_reference_table +--------------------------------------------------------------------- + +(1 row) + CREATE TABLE citus_local_table(a int, b int); -SELECT create_citus_local_table('citus_local_table'); - create_citus_local_table ---------------------------------------------------------------------- - -(1 row) - +ALTER TABLE citus_local_table ADD CONSTRAINT fkey_to_dummy_1 FOREIGN KEY (a) REFERENCES dummy_reference_table(a); +NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1510001, 'citus_local_table_queries_mx', 1510000, 'citus_local_table_queries_mx', 'ALTER TABLE citus_local_table ADD CONSTRAINT fkey_to_dummy_1 FOREIGN KEY (a) REFERENCES dummy_reference_table(a);') CREATE TABLE citus_local_table_2(a int, b int); -SELECT create_citus_local_table('citus_local_table_2'); - create_citus_local_table ---------------------------------------------------------------------- - -(1 row) - +ALTER TABLE citus_local_table_2 ADD CONSTRAINT fkey_to_dummy_2 FOREIGN KEY (a) REFERENCES dummy_reference_table(a); +NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1510002, 'citus_local_table_queries_mx', 1510000, 'citus_local_table_queries_mx', 'ALTER TABLE citus_local_table_2 ADD CONSTRAINT fkey_to_dummy_2 FOREIGN KEY (a) REFERENCES dummy_reference_table(a);') CREATE TABLE reference_table(a int, b int); SELECT create_reference_table('reference_table'); create_reference_table @@ -63,8 +62,9 @@ CREATE FUNCTION clear_and_init_test_tables() RETURNS void AS $$ BEGIN SET client_min_messages to ERROR; - TRUNCATE postgres_local_table, citus_local_table, reference_table, distributed_table; + TRUNCATE postgres_local_table, citus_local_table, reference_table, distributed_table, dummy_reference_table, citus_local_table_2; + INSERT INTO dummy_reference_table SELECT i, i FROM generate_series(0, 5) i; INSERT INTO citus_local_table SELECT i, i FROM generate_series(0, 5) i; INSERT INTO citus_local_table_2 SELECT i, i FROM generate_series(0, 5) i; INSERT INTO postgres_local_table SELECT i, i FROM generate_series(0, 5) i; @@ -734,7 +734,7 @@ JOIN (SELECT count(*) as a, count(*) as b USING (a); a | b --------------------------------------------------------------------- - 0 | 0 + 1 | 1 (1 row) -- direct join inside CTE not supported @@ -801,7 +801,7 @@ LIMIT 10; -> Limit -> Sort Sort Key: distributed_table.* - -> Seq Scan on distributed_table_1510003 distributed_table + -> Seq Scan on distributed_table_1510004 distributed_table (14 rows) -- show that we do not pull to coordinator @@ -815,8 +815,8 @@ SELECT * FROM citus_local_table; Tasks Shown: All -> Task Node: host=localhost port=xxxxx dbname=regression - -> Insert on citus_local_table_1510000 citus_table_alias - -> Seq Scan on citus_local_table_1510000 citus_local_table + -> Insert on citus_local_table_1510001 citus_table_alias + -> Seq Scan on citus_local_table_1510001 citus_local_table (7 rows) EXPLAIN (COSTS FALSE) @@ -829,8 +829,8 @@ SELECT reference_table.* FROM reference_table; Tasks Shown: All -> Task Node: host=localhost port=xxxxx dbname=regression - -> Insert on citus_local_table_1510000 citus_table_alias - -> Seq Scan on reference_table_1510002 reference_table + -> Insert on citus_local_table_1510001 citus_table_alias + -> Seq Scan on reference_table_1510003 reference_table (7 rows) EXPLAIN (COSTS FALSE) @@ -846,7 +846,7 @@ SELECT reference_table.* FROM reference_table, postgres_local_table; -> Task Node: host=localhost port=xxxxx dbname=regression -> Nested Loop - -> Seq Scan on reference_table_1510002 reference_table + -> Seq Scan on reference_table_1510003 reference_table -> Materialize -> Seq Scan on postgres_local_table (11 rows) @@ -865,9 +865,9 @@ SELECT reference_table.* FROM reference_table, distributed_table; -> Task Node: host=localhost port=xxxxx dbname=regression -> Nested Loop - -> Seq Scan on distributed_table_1510003 distributed_table + -> Seq Scan on distributed_table_1510004 distributed_table -> Materialize - -> Seq Scan on reference_table_1510002 reference_table + -> Seq Scan on reference_table_1510003 reference_table (11 rows) -- truncate tables & add unique constraints to be able to define foreign keys @@ -983,8 +983,8 @@ BEGIN; (2 rows) SAVEPOINT sp2; - INSERT INTO citus_local_table VALUES (5), (6); - INSERT INTO distributed_table VALUES (5), (6); + INSERT INTO citus_local_table VALUES (3), (4); + INSERT INTO distributed_table VALUES (3), (4); ROLLBACK TO SAVEPOINT sp2; SELECT * FROM citus_local_table ORDER BY 1,2; a | b @@ -999,8 +999,8 @@ BEGIN; (0 rows) SAVEPOINT sp3; - INSERT INTO citus_local_table VALUES (7), (8); - INSERT INTO reference_table VALUES (7), (8); + INSERT INTO citus_local_table VALUES (3), (2); + INSERT INTO reference_table VALUES (3), (2); ROLLBACK TO SAVEPOINT sp3; SELECT * FROM citus_local_table ORDER BY 1,2; a | b @@ -1018,4 +1018,4 @@ COMMIT; \c - - - :master_port -- cleanup at exit DROP SCHEMA citus_local_table_queries_mx CASCADE; -NOTICE: drop cascades to 7 other objects +NOTICE: drop cascades to 9 other objects diff --git a/src/test/regress/expected/multi_extension.out b/src/test/regress/expected/multi_extension.out index a56701ca9..9eb9f3c4a 100644 --- a/src/test/regress/expected/multi_extension.out +++ b/src/test/regress/expected/multi_extension.out @@ -499,9 +499,9 @@ SELECT * FROM print_extension_changes(); | function worker_change_sequence_dependency(regclass,regclass,regclass) | schema columnar | sequence columnar.storageid_seq - | table columnar.columnar_skipnodes - | table columnar.columnar_stripes + | table columnar.chunk | table columnar.options + | table columnar.stripe | view citus_shards | view citus_tables | view time_partitions diff --git a/src/test/regress/expected/multi_extension_0.out b/src/test/regress/expected/multi_extension_0.out index 89d4382b3..8f2fe75d7 100644 --- a/src/test/regress/expected/multi_extension_0.out +++ b/src/test/regress/expected/multi_extension_0.out @@ -495,9 +495,9 @@ SELECT * FROM print_extension_changes(); | function worker_change_sequence_dependency(regclass,regclass,regclass) | schema columnar | sequence columnar.storageid_seq - | table columnar.columnar_skipnodes - | table columnar.columnar_stripes + | table columnar.chunk | table columnar.options + | table columnar.stripe | view citus_shards | view citus_tables | view time_partitions diff --git a/src/test/regress/expected/ref_citus_local_fkeys.out b/src/test/regress/expected/ref_citus_local_fkeys.out index 44d723404..d8eaaf318 100644 --- a/src/test/regress/expected/ref_citus_local_fkeys.out +++ b/src/test/regress/expected/ref_citus_local_fkeys.out @@ -221,6 +221,19 @@ BEGIN; ALTER TABLE citus_local_table_1 ADD CONSTRAINT multi_fkey FOREIGN KEY (a, b) REFERENCES citus_local_table_2(a, b); NOTICE: executing the command locally: SELECT worker_apply_inter_shard_ddl_command (1506004, 'ref_citus_local_fkeys', 1506005, 'ref_citus_local_fkeys', 'ALTER TABLE citus_local_table_1 ADD CONSTRAINT multi_fkey FOREIGN KEY (a, b) REFERENCES citus_local_table_2(a, b);') COMMIT; +-- when local execution is disabled, citus local table cannot be created +BEGIN; + SET citus.enable_local_execution TO false; + CREATE TABLE referenced_table(id int primary key); + SELECT create_reference_table('referenced_table'); + create_reference_table +--------------------------------------------------------------------- + +(1 row) + + CREATE TABLE referencing_table(id int, ref_id int, FOREIGN KEY(ref_id) REFERENCES referenced_table(id) ON DELETE SET DEFAULT); +ERROR: cannot switch local execution status from local execution disabled to local execution enabled since it can cause visibility problems in the current transaction +ROLLBACK; -- cleanup at exit DROP SCHEMA ref_citus_local_fkeys CASCADE; NOTICE: drop cascades to 6 other objects diff --git a/src/test/regress/expected/undistribute_table_cascade.out b/src/test/regress/expected/undistribute_table_cascade.out index 75c736324..3bfd63bb9 100644 --- a/src/test/regress/expected/undistribute_table_cascade.out +++ b/src/test/regress/expected/undistribute_table_cascade.out @@ -527,10 +527,11 @@ BEGIN; ROLLBACK; BEGIN; + ALTER TABLE reference_table_2 DROP CONSTRAINT fkey_5; ALTER TABLE reference_table_2 DROP CONSTRAINT fkey_7; - -- since now citus_local_table_2 has no foreign keys, show that + -- since now reference_table_2 has no foreign keys, show that -- cascade_via_foreign_keys option still works fine - SELECT undistribute_table('citus_local_table_2', cascade_via_foreign_keys=>true); + SELECT undistribute_table('reference_table_2', cascade_via_foreign_keys=>true); undistribute_table --------------------------------------------------------------------- @@ -539,7 +540,7 @@ BEGIN; SELECT COUNT(*)=0 FROM pg_dist_partition, pg_tables WHERE tablename=logicalrelid::regclass::text AND schemaname='undistribute_table_cascade' AND - tablename='citus_local_table_2'; + tablename='reference_table_2'; ?column? --------------------------------------------------------------------- t diff --git a/src/test/regress/expected/upgrade_list_citus_objects.out b/src/test/regress/expected/upgrade_list_citus_objects.out index 00cb067f5..fb457b069 100644 --- a/src/test/regress/expected/upgrade_list_citus_objects.out +++ b/src/test/regress/expected/upgrade_list_citus_objects.out @@ -209,9 +209,9 @@ ORDER BY 1; sequence pg_dist_placement_placementid_seq sequence pg_dist_shardid_seq table citus.pg_dist_object - table columnar.columnar_skipnodes - table columnar.columnar_stripes + table columnar.chunk table columnar.options + table columnar.stripe table pg_dist_authinfo table pg_dist_colocation table pg_dist_local_group diff --git a/src/test/regress/expected/upgrade_list_citus_objects_0.out b/src/test/regress/expected/upgrade_list_citus_objects_0.out index d9980d8bf..12fba4705 100644 --- a/src/test/regress/expected/upgrade_list_citus_objects_0.out +++ b/src/test/regress/expected/upgrade_list_citus_objects_0.out @@ -205,9 +205,9 @@ ORDER BY 1; sequence pg_dist_placement_placementid_seq sequence pg_dist_shardid_seq table citus.pg_dist_object - table columnar.columnar_skipnodes - table columnar.columnar_stripes + table columnar.chunk table columnar.options + table columnar.stripe table pg_dist_authinfo table pg_dist_colocation table pg_dist_local_group diff --git a/src/test/regress/input/am_chunk_filtering.source b/src/test/regress/input/am_chunk_filtering.source index 4020f9499..41c098528 100644 --- a/src/test/regress/input/am_chunk_filtering.source +++ b/src/test/regress/input/am_chunk_filtering.source @@ -71,3 +71,9 @@ B \. SELECT * FROM collation_chunk_filtering_test WHERE A > 'B'; + +CREATE TABLE simple_chunk_filtering(i int) USING COLUMNAR; +INSERT INTO simple_chunk_filtering SELECT generate_series(0,234567); +EXPLAIN (analyze on, costs off, timing off, summary off) + SELECT * FROM simple_chunk_filtering WHERE i > 123456; +DROP TABLE simple_chunk_filtering; diff --git a/src/test/regress/input/am_data_types.source b/src/test/regress/input/am_data_types.source index ddb543a69..2b8dbbeee 100644 --- a/src/test/regress/input/am_data_types.source +++ b/src/test/regress/input/am_data_types.source @@ -66,3 +66,8 @@ CREATE TABLE test_null_values (a int, b int[], c composite_type) COPY test_null_values FROM '@abs_srcdir@/data/null_values.csv' WITH CSV; SELECT * FROM test_null_values; + +CREATE TABLE test_json(j json) USING columnar; +INSERT INTO test_json SELECT ('{"att": ' || g::text || '}')::json from generate_series(1,1000000) g; +SELECT * FROM test_json WHERE (j->'att')::text::int8 > 999990; +DROP TABLE test_json; diff --git a/src/test/regress/output/am_chunk_filtering.source b/src/test/regress/output/am_chunk_filtering.source index ff52a618c..9a42d7230 100644 --- a/src/test/regress/output/am_chunk_filtering.source +++ b/src/test/regress/output/am_chunk_filtering.source @@ -118,3 +118,16 @@ SELECT * FROM collation_chunk_filtering_test WHERE A > 'B'; Å (1 row) +CREATE TABLE simple_chunk_filtering(i int) USING COLUMNAR; +INSERT INTO simple_chunk_filtering SELECT generate_series(0,234567); +EXPLAIN (analyze on, costs off, timing off, summary off) + SELECT * FROM simple_chunk_filtering WHERE i > 123456; + QUERY PLAN +--------------------------------------------------------------------- + Custom Scan (ColumnarScan) on simple_chunk_filtering (actual rows=111111 loops=1) + Filter: (i > 123456) + Rows Removed by Filter: 3457 + Columnar Chunks Removed by Filter: 12 +(4 rows) + +DROP TABLE simple_chunk_filtering; diff --git a/src/test/regress/output/am_data_types.source b/src/test/regress/output/am_data_types.source index 3c79c6cfe..45778f0a3 100644 --- a/src/test/regress/output/am_data_types.source +++ b/src/test/regress/output/am_data_types.source @@ -76,3 +76,21 @@ SELECT * FROM test_null_values; | | (2 rows) +CREATE TABLE test_json(j json) USING columnar; +INSERT INTO test_json SELECT ('{"att": ' || g::text || '}')::json from generate_series(1,1000000) g; +SELECT * FROM test_json WHERE (j->'att')::text::int8 > 999990; + j +--------------------------------------------------------------------- + {"att": 999991} + {"att": 999992} + {"att": 999993} + {"att": 999994} + {"att": 999995} + {"att": 999996} + {"att": 999997} + {"att": 999998} + {"att": 999999} + {"att": 1000000} +(10 rows) + +DROP TABLE test_json; diff --git a/src/test/regress/sql/am_drop.sql b/src/test/regress/sql/am_drop.sql index 06a110bf3..265ff6e2e 100644 --- a/src/test/regress/sql/am_drop.sql +++ b/src/test/regress/sql/am_drop.sql @@ -15,23 +15,23 @@ -- store postgres database oid SELECT oid postgres_oid FROM pg_database WHERE datname = 'postgres' \gset -SELECT count(distinct storageid) AS columnar_stripes_before_drop FROM columnar.columnar_stripes \gset +SELECT count(distinct storageid) AS columnar_stripes_before_drop FROM columnar.stripe \gset -- DROP columnar tables DROP TABLE contestant; DROP TABLE contestant_compressed; -- make sure DROP deletes metadata -SELECT :columnar_stripes_before_drop - count(distinct storageid) FROM columnar.columnar_stripes; +SELECT :columnar_stripes_before_drop - count(distinct storageid) FROM columnar.stripe; -- Create a columnar table under a schema and drop it. CREATE SCHEMA test_schema; CREATE TABLE test_schema.test_table(data int) USING columnar; INSERT INTO test_schema.test_table VALUES (1); -SELECT count(*) AS columnar_stripes_before_drop FROM columnar.columnar_stripes \gset +SELECT count(*) AS columnar_stripes_before_drop FROM columnar.stripe \gset DROP SCHEMA test_schema CASCADE; -SELECT :columnar_stripes_before_drop - count(distinct storageid) FROM columnar.columnar_stripes; +SELECT :columnar_stripes_before_drop - count(distinct storageid) FROM columnar.stripe; SELECT current_database() datname \gset diff --git a/src/test/regress/sql/am_matview.sql b/src/test/regress/sql/am_matview.sql index 74849303e..992741282 100644 --- a/src/test/regress/sql/am_matview.sql +++ b/src/test/regress/sql/am_matview.sql @@ -38,11 +38,11 @@ SELECT * FROM t_view a ORDER BY a; SELECT columnar_relation_storageid(oid) AS storageid FROM pg_class WHERE relname='t_view' \gset -SELECT count(*) FROM columnar.columnar_stripes WHERE storageid=:storageid; -SELECT count(*) FROM columnar.columnar_skipnodes WHERE storageid=:storageid; +SELECT count(*) FROM columnar.stripe WHERE storageid=:storageid; +SELECT count(*) FROM columnar.chunk WHERE storageid=:storageid; DROP TABLE t CASCADE; -- dropping must remove metadata -SELECT count(*) FROM columnar.columnar_stripes WHERE storageid=:storageid; -SELECT count(*) FROM columnar.columnar_skipnodes WHERE storageid=:storageid; +SELECT count(*) FROM columnar.stripe WHERE storageid=:storageid; +SELECT count(*) FROM columnar.chunk WHERE storageid=:storageid; diff --git a/src/test/regress/sql/am_recursive.sql b/src/test/regress/sql/am_recursive.sql index f3e9bd39e..d7e48f1d5 100644 --- a/src/test/regress/sql/am_recursive.sql +++ b/src/test/regress/sql/am_recursive.sql @@ -15,7 +15,7 @@ INSERT INTO t2 SELECT i, f(i) FROM generate_series(1, 5) i; -- there are no subtransactions, so above statement should batch -- INSERTs inside the UDF and create on stripe per table. -SELECT relname, count(*) FROM columnar.columnar_stripes a, pg_class b +SELECT relname, count(*) FROM columnar.stripe a, pg_class b WHERE columnar_relation_storageid(b.oid)=a.storageid AND relname IN ('t1', 't2') GROUP BY relname ORDER BY relname; diff --git a/src/test/regress/sql/am_rollback.sql b/src/test/regress/sql/am_rollback.sql index 265c56ce8..ddc7149e0 100644 --- a/src/test/regress/sql/am_rollback.sql +++ b/src/test/regress/sql/am_rollback.sql @@ -5,7 +5,7 @@ CREATE TABLE t(a int, b int) USING columnar; CREATE VIEW t_stripes AS -SELECT * FROM columnar.columnar_stripes a, pg_class b +SELECT * FROM columnar.stripe a, pg_class b WHERE a.storageid = columnar_relation_storageid(b.oid) AND b.relname = 't'; BEGIN; diff --git a/src/test/regress/sql/am_truncate.sql b/src/test/regress/sql/am_truncate.sql index 6340d0ceb..e284b858f 100644 --- a/src/test/regress/sql/am_truncate.sql +++ b/src/test/regress/sql/am_truncate.sql @@ -13,7 +13,7 @@ CREATE TABLE columnar_truncate_test_second (a int, b int) USING columnar; CREATE TABLE columnar_truncate_test_compressed (a int, b int) USING columnar; CREATE TABLE columnar_truncate_test_regular (a int, b int); -SELECT count(distinct storageid) AS columnar_data_files_before_truncate FROM columnar.columnar_stripes \gset +SELECT count(distinct storageid) AS columnar_data_files_before_truncate FROM columnar.stripe \gset INSERT INTO columnar_truncate_test select a, a from generate_series(1, 10) a; @@ -63,7 +63,7 @@ TRUNCATE TABLE columnar_truncate_test; SELECT * from columnar_truncate_test; -- make sure TRUNATE deletes metadata for old relfilenode -SELECT :columnar_data_files_before_truncate - count(distinct storageid) FROM columnar.columnar_stripes; +SELECT :columnar_data_files_before_truncate - count(distinct storageid) FROM columnar.stripe; -- test if truncation in the same transaction that created the table works properly BEGIN; @@ -74,7 +74,7 @@ INSERT INTO columnar_same_transaction_truncate SELECT * FROM generate_series(20, COMMIT; -- should output "1" for the newly created relation -SELECT count(distinct storageid) - :columnar_data_files_before_truncate FROM columnar.columnar_stripes; +SELECT count(distinct storageid) - :columnar_data_files_before_truncate FROM columnar.stripe; SELECT * FROM columnar_same_transaction_truncate; DROP TABLE columnar_same_transaction_truncate; diff --git a/src/test/regress/sql/am_vacuum.sql b/src/test/regress/sql/am_vacuum.sql index 2142103ce..c0bd661fa 100644 --- a/src/test/regress/sql/am_vacuum.sql +++ b/src/test/regress/sql/am_vacuum.sql @@ -1,11 +1,11 @@ SET columnar.compression TO 'none'; -SELECT count(distinct storageid) AS columnar_table_count FROM columnar.columnar_stripes \gset +SELECT count(distinct storageid) AS columnar_table_count FROM columnar.stripe \gset CREATE TABLE t(a int, b int) USING columnar; CREATE VIEW t_stripes AS -SELECT * FROM columnar.columnar_stripes a, pg_class b +SELECT * FROM columnar.stripe a, pg_class b WHERE a.storageid = columnar_relation_storageid(b.oid) AND b.relname='t'; SELECT count(*) FROM t_stripes; @@ -38,18 +38,18 @@ SELECT count(*) FROM t_stripes; -- VACUUM FULL doesn't reclaim dropped columns, but converts them to NULLs ALTER TABLE t DROP COLUMN a; -SELECT stripe, attr, chunk, minimum_value IS NULL, maximum_value IS NULL -FROM columnar.columnar_skipnodes a, pg_class b +SELECT stripeid, attnum, chunkid, minimum_value IS NULL, maximum_value IS NULL +FROM columnar.chunk a, pg_class b WHERE a.storageid = columnar_relation_storageid(b.oid) AND b.relname='t' ORDER BY 1, 2, 3; VACUUM FULL t; -SELECT stripe, attr, chunk, minimum_value IS NULL, maximum_value IS NULL -FROM columnar.columnar_skipnodes a, pg_class b +SELECT stripeid, attnum, chunkid, minimum_value IS NULL, maximum_value IS NULL +FROM columnar.chunk a, pg_class b WHERE a.storageid = columnar_relation_storageid(b.oid) AND b.relname='t' ORDER BY 1, 2, 3; -- Make sure we cleaned-up the transient table metadata after VACUUM FULL commands -SELECT count(distinct storageid) - :columnar_table_count FROM columnar.columnar_stripes; +SELECT count(distinct storageid) - :columnar_table_count FROM columnar.stripe; -- do this in a transaction so concurrent autovacuum doesn't interfere with results BEGIN; @@ -112,7 +112,7 @@ DROP TABLE t; DROP VIEW t_stripes; -- Make sure we cleaned the metadata for t too -SELECT count(distinct storageid) - :columnar_table_count FROM columnar.columnar_stripes; +SELECT count(distinct storageid) - :columnar_table_count FROM columnar.stripe; -- A table with high compression ratio SET columnar.compression TO 'pglz'; diff --git a/src/test/regress/sql/citus_local_table_triggers.sql b/src/test/regress/sql/citus_local_table_triggers.sql index 05f1a8149..efb63ebd5 100644 --- a/src/test/regress/sql/citus_local_table_triggers.sql +++ b/src/test/regress/sql/citus_local_table_triggers.sql @@ -13,8 +13,13 @@ SET client_min_messages to ERROR; SELECT 1 FROM master_add_node('localhost', :master_port, groupId => 0); RESET client_min_messages; +CREATE TABLE dummy_reference_table(a int unique, b int); +INSERT INTO dummy_reference_table SELECT i FROM generate_series(-1, 5) i; +INSERT INTO dummy_reference_table VALUES (99),(100),(599),(600); +SELECT create_reference_table('dummy_reference_table'); + CREATE TABLE citus_local_table (value int); -SELECT create_citus_local_table('citus_local_table'); +ALTER TABLE citus_local_table ADD CONSTRAINT fkey_to_dummy_1 FOREIGN KEY (value) REFERENCES dummy_reference_table(a); -------------------- -- DELETE trigger -- @@ -141,14 +146,15 @@ BEGIN; AFTER TRUNCATE ON "interesting!schema"."citus_local!_table" FOR EACH STATEMENT EXECUTE FUNCTION dummy_function(); - SELECT create_citus_local_table('"interesting!schema"."citus_local!_table"'); + ALTER TABLE "interesting!schema"."citus_local!_table" ADD CONSTRAINT fkey_to_dummy_2 FOREIGN KEY (value) REFERENCES dummy_reference_table(a); -- we shouldn't see truncate trigger on shard relation as we drop it - SELECT * FROM citus_local_table_triggers; + SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; ROLLBACK; CREATE TABLE "interesting!schema"."citus_local!_table"(value int); -SELECT create_citus_local_table('"interesting!schema"."citus_local!_table"'); +ALTER TABLE "interesting!schema"."citus_local!_table" ADD CONSTRAINT fkey_to_dummy_2 FOREIGN KEY (value) REFERENCES dummy_reference_table(a); CREATE TRIGGER "trigger\'name" BEFORE INSERT ON "interesting!schema"."citus_local!_table" @@ -168,21 +174,25 @@ BEGIN; DROP EXTENSION seg; -- show that dropping extension drops the triggers automatically - SELECT * FROM citus_local_table_triggers; + SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; ROLLBACK; -- ALTER TRIGGER RENAME ALTER TRIGGER "trigger\'name" ON "interesting!schema"."citus_local!_table" RENAME TO "trigger\'name22"; -- show that triggers on both shell relation and shard relation are renamed -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; -- ALTER TABLE DISABLE trigger ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER "trigger\'name22"; -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; -- ALTER TABLE ENABLE trigger ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER "trigger\'name22"; -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; CREATE TRIGGER another_trigger AFTER DELETE ON "interesting!schema"."citus_local!_table" @@ -190,24 +200,29 @@ FOR EACH STATEMENT EXECUTE FUNCTION dummy_function(); ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER USER; -- show that all triggers except the internal ones are disabled -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER USER; -- show that all triggers except the internal ones are enabled again -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER ALL; -- show that all triggers including internal triggers are disabled -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER ALL; -- show that all triggers including internal triggers are enabled again -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; DROP TRIGGER another_trigger ON "interesting!schema"."citus_local!_table"; DROP TRIGGER "trigger\'name22" ON "interesting!schema"."citus_local!_table"; -- show that drop trigger works as expected -SELECT * FROM citus_local_table_triggers; +SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; BEGIN; CREATE TRIGGER "another_trigger\'name" @@ -216,11 +231,13 @@ BEGIN; ALTER TABLE "interesting!schema"."citus_local!_table" DISABLE TRIGGER "another_trigger\'name"; -- show that our truncate trigger is disabled .. - SELECT * FROM citus_local_table_triggers; + SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; ALTER TABLE "interesting!schema"."citus_local!_table" ENABLE TRIGGER ALL; -- .. and now it is enabled back - SELECT * FROM citus_local_table_triggers; + SELECT * FROM citus_local_table_triggers + WHERE tgname NOT LIKE 'RI_ConstraintTrigger%'; ROLLBACK; -- as we create ddl jobs for DROP TRIGGER before standard process utility, diff --git a/src/test/regress/sql/citus_local_tables_queries.sql b/src/test/regress/sql/citus_local_tables_queries.sql index f98ead754..a4f8b6e00 100644 --- a/src/test/regress/sql/citus_local_tables_queries.sql +++ b/src/test/regress/sql/citus_local_tables_queries.sql @@ -13,11 +13,14 @@ SET client_min_messages to ERROR; SELECT 1 FROM master_add_node('localhost', :master_port, groupId => 0); RESET client_min_messages; +CREATE TABLE dummy_reference_table(a int unique, b int); +SELECT create_reference_table('dummy_reference_table'); + CREATE TABLE citus_local_table(a int, b int); -SELECT create_citus_local_table('citus_local_table'); +ALTER TABLE citus_local_table ADD CONSTRAINT fkey_to_dummy_1 FOREIGN KEY (a) REFERENCES dummy_reference_table(a); CREATE TABLE citus_local_table_2(a int, b int); -SELECT create_citus_local_table('citus_local_table_2'); +ALTER TABLE citus_local_table_2 ADD CONSTRAINT fkey_to_dummy_2 FOREIGN KEY (a) REFERENCES dummy_reference_table(a); CREATE TABLE reference_table(a int, b int); SELECT create_reference_table('reference_table'); @@ -37,8 +40,9 @@ CREATE FUNCTION clear_and_init_test_tables() RETURNS void AS $$ BEGIN SET client_min_messages to ERROR; - TRUNCATE postgres_local_table, citus_local_table, reference_table, distributed_table; + TRUNCATE postgres_local_table, citus_local_table, reference_table, distributed_table, dummy_reference_table, citus_local_table_2; + INSERT INTO dummy_reference_table SELECT i, i FROM generate_series(0, 5) i; INSERT INTO citus_local_table SELECT i, i FROM generate_series(0, 5) i; INSERT INTO citus_local_table_2 SELECT i, i FROM generate_series(0, 5) i; INSERT INTO postgres_local_table SELECT i, i FROM generate_series(0, 5) i; @@ -616,16 +620,16 @@ BEGIN; SELECT * FROM citus_local_table ORDER BY 1,2; SAVEPOINT sp2; - INSERT INTO citus_local_table VALUES (5), (6); - INSERT INTO distributed_table VALUES (5), (6); + INSERT INTO citus_local_table VALUES (3), (4); + INSERT INTO distributed_table VALUES (3), (4); ROLLBACK TO SAVEPOINT sp2; SELECT * FROM citus_local_table ORDER BY 1,2; SELECT * FROM distributed_table ORDER BY 1,2; SAVEPOINT sp3; - INSERT INTO citus_local_table VALUES (7), (8); - INSERT INTO reference_table VALUES (7), (8); + INSERT INTO citus_local_table VALUES (3), (2); + INSERT INTO reference_table VALUES (3), (2); ROLLBACK TO SAVEPOINT sp3; SELECT * FROM citus_local_table ORDER BY 1,2; diff --git a/src/test/regress/sql/citus_local_tables_queries_mx.sql b/src/test/regress/sql/citus_local_tables_queries_mx.sql index 17586333f..b1a9e4622 100644 --- a/src/test/regress/sql/citus_local_tables_queries_mx.sql +++ b/src/test/regress/sql/citus_local_tables_queries_mx.sql @@ -17,11 +17,14 @@ RESET client_min_messages; SELECT start_metadata_sync_to_node('localhost', :worker_1_port); SET citus.replication_model TO streaming; +CREATE TABLE dummy_reference_table(a int unique, b int); +SELECT create_reference_table('dummy_reference_table'); + CREATE TABLE citus_local_table(a int, b int); -SELECT create_citus_local_table('citus_local_table'); +ALTER TABLE citus_local_table ADD CONSTRAINT fkey_to_dummy_1 FOREIGN KEY (a) REFERENCES dummy_reference_table(a); CREATE TABLE citus_local_table_2(a int, b int); -SELECT create_citus_local_table('citus_local_table_2'); +ALTER TABLE citus_local_table_2 ADD CONSTRAINT fkey_to_dummy_2 FOREIGN KEY (a) REFERENCES dummy_reference_table(a); CREATE TABLE reference_table(a int, b int); SELECT create_reference_table('reference_table'); @@ -44,8 +47,9 @@ CREATE FUNCTION clear_and_init_test_tables() RETURNS void AS $$ BEGIN SET client_min_messages to ERROR; - TRUNCATE postgres_local_table, citus_local_table, reference_table, distributed_table; + TRUNCATE postgres_local_table, citus_local_table, reference_table, distributed_table, dummy_reference_table, citus_local_table_2; + INSERT INTO dummy_reference_table SELECT i, i FROM generate_series(0, 5) i; INSERT INTO citus_local_table SELECT i, i FROM generate_series(0, 5) i; INSERT INTO citus_local_table_2 SELECT i, i FROM generate_series(0, 5) i; INSERT INTO postgres_local_table SELECT i, i FROM generate_series(0, 5) i; @@ -638,16 +642,16 @@ BEGIN; SELECT * FROM citus_local_table ORDER BY 1,2; SAVEPOINT sp2; - INSERT INTO citus_local_table VALUES (5), (6); - INSERT INTO distributed_table VALUES (5), (6); + INSERT INTO citus_local_table VALUES (3), (4); + INSERT INTO distributed_table VALUES (3), (4); ROLLBACK TO SAVEPOINT sp2; SELECT * FROM citus_local_table ORDER BY 1,2; SELECT * FROM distributed_table ORDER BY 1,2; SAVEPOINT sp3; - INSERT INTO citus_local_table VALUES (7), (8); - INSERT INTO reference_table VALUES (7), (8); + INSERT INTO citus_local_table VALUES (3), (2); + INSERT INTO reference_table VALUES (3), (2); ROLLBACK TO SAVEPOINT sp3; SELECT * FROM citus_local_table ORDER BY 1,2; diff --git a/src/test/regress/sql/ref_citus_local_fkeys.sql b/src/test/regress/sql/ref_citus_local_fkeys.sql index 6a23e43ef..18f2a1d5a 100644 --- a/src/test/regress/sql/ref_citus_local_fkeys.sql +++ b/src/test/regress/sql/ref_citus_local_fkeys.sql @@ -148,5 +148,13 @@ BEGIN; ALTER TABLE citus_local_table_1 ADD CONSTRAINT multi_fkey FOREIGN KEY (a, b) REFERENCES citus_local_table_2(a, b); COMMIT; +-- when local execution is disabled, citus local table cannot be created +BEGIN; + SET citus.enable_local_execution TO false; + CREATE TABLE referenced_table(id int primary key); + SELECT create_reference_table('referenced_table'); + CREATE TABLE referencing_table(id int, ref_id int, FOREIGN KEY(ref_id) REFERENCES referenced_table(id) ON DELETE SET DEFAULT); +ROLLBACK; + -- cleanup at exit DROP SCHEMA ref_citus_local_fkeys CASCADE; diff --git a/src/test/regress/sql/undistribute_table_cascade.sql b/src/test/regress/sql/undistribute_table_cascade.sql index b0c446838..d2f347ba5 100644 --- a/src/test/regress/sql/undistribute_table_cascade.sql +++ b/src/test/regress/sql/undistribute_table_cascade.sql @@ -354,16 +354,17 @@ BEGIN; ROLLBACK; BEGIN; + ALTER TABLE reference_table_2 DROP CONSTRAINT fkey_5; ALTER TABLE reference_table_2 DROP CONSTRAINT fkey_7; - -- since now citus_local_table_2 has no foreign keys, show that + -- since now reference_table_2 has no foreign keys, show that -- cascade_via_foreign_keys option still works fine - SELECT undistribute_table('citus_local_table_2', cascade_via_foreign_keys=>true); + SELECT undistribute_table('reference_table_2', cascade_via_foreign_keys=>true); SELECT COUNT(*)=0 FROM pg_dist_partition, pg_tables WHERE tablename=logicalrelid::regclass::text AND schemaname='undistribute_table_cascade' AND - tablename='citus_local_table_2'; + tablename='reference_table_2'; ROLLBACK; CREATE SCHEMA "bad!schemaName";