mirror of https://github.com/citusdata/citus.git
Bugfix for deparsing INSERT..SELECT queries which involve constant values
This commit fixes a bug when the SELECT target list includes a constant value. Previous behaviour of target list re-ordering: * Iterate over the INSERT target list * If it includes a Var, find the corresponding SELECT entry and update its resno accordingly * If it does not include a Var (which we only considered to be DEFAULTs), generate a new SELECT target entry * If the processed target entry count in SELECT target list is less than the original SELECT target list (GROUP BY elements not included in the SELECT target entry), add them in the SELECT target list and update the resnos accordingly. * However, this step was leading to add the CONST SELECT target entries twice. The reason is that when CONST target list entries appear in the SELECT target list, the INSERT target list doesn't include a Var. Instead, it includes CONST as it does for DEFAULTs. New behaviour of target list re-ordering: * Iterate over the INSERT target list * If it includes a Var, find the corresponding SELECT entry and update its resno accordingly * If it does not include a Var (which we consider to be DEFAULTs and CONSTs on the SELECT), generate a new SELECT target entry * If any target entry remains on the SELECT target list which are resjunk, (GROUP BY elements not included in the SELECT target entry), keep them in the SELECT target list by updating the resnos.pull/988/head
parent
86e3086ac8
commit
df974e15b8
|
@ -2422,9 +2422,9 @@ ReorderInsertSelectTargetLists(Query *originalQuery, RangeTblEntry *insertRte,
|
|||
List *newInsertTargetlist = NIL;
|
||||
int resno = 1;
|
||||
Index insertTableId = 1;
|
||||
int updatedSubqueryEntryCount = 0;
|
||||
Oid insertRelationId = InvalidOid;
|
||||
int subqueryTargetLength = 0;
|
||||
int targetEntryIndex = 0;
|
||||
|
||||
AssertArg(InsertSelectQuery(originalQuery));
|
||||
|
||||
|
@ -2437,8 +2437,9 @@ ReorderInsertSelectTargetLists(Query *originalQuery, RangeTblEntry *insertRte,
|
|||
* - Iterate over the INSERT target list entries
|
||||
* - If the target entry includes a Var, find the corresponding
|
||||
* SELECT target entry on the original query and update resno
|
||||
* - If the target entry does not include a Var (i.e., defaults),
|
||||
* create new target entry and add that to SELECT target list
|
||||
* - If the target entry does not include a Var (i.e., defaults
|
||||
* or constants), create new target entry and add that to
|
||||
* SELECT target list
|
||||
* - Create a new INSERT target entry with respect to the new
|
||||
* SELECT target entry created.
|
||||
*/
|
||||
|
@ -2453,7 +2454,6 @@ ReorderInsertSelectTargetLists(Query *originalQuery, RangeTblEntry *insertRte,
|
|||
AttrNumber originalAttrNo = get_attnum(insertRelationId,
|
||||
oldInsertTargetEntry->resname);
|
||||
|
||||
|
||||
/* see transformInsertRow() for the details */
|
||||
if (IsA(oldInsertTargetEntry->expr, ArrayRef) ||
|
||||
IsA(oldInsertTargetEntry->expr, FieldStore))
|
||||
|
@ -2493,8 +2493,6 @@ ReorderInsertSelectTargetLists(Query *originalQuery, RangeTblEntry *insertRte,
|
|||
newSubqueryTargetEntry->resno = resno;
|
||||
newSubqueryTargetlist = lappend(newSubqueryTargetlist,
|
||||
newSubqueryTargetEntry);
|
||||
|
||||
updatedSubqueryEntryCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2506,6 +2504,13 @@ ReorderInsertSelectTargetLists(Query *originalQuery, RangeTblEntry *insertRte,
|
|||
newSubqueryTargetEntry);
|
||||
}
|
||||
|
||||
/*
|
||||
* The newly created select target entry cannot be a junk entry since junk
|
||||
* entries are not in the final target list and we're processing the
|
||||
* final target list entries.
|
||||
*/
|
||||
Assert(!newSubqueryTargetEntry->resjunk);
|
||||
|
||||
newInsertVar = makeVar(insertTableId, originalAttrNo,
|
||||
exprType((Node *) newSubqueryTargetEntry->expr),
|
||||
exprTypmod((Node *) newSubqueryTargetEntry->expr),
|
||||
|
@ -2524,17 +2529,22 @@ ReorderInsertSelectTargetLists(Query *originalQuery, RangeTblEntry *insertRte,
|
|||
* target list of subquery), update the remaining resnos.
|
||||
*/
|
||||
subqueryTargetLength = list_length(subquery->targetList);
|
||||
if (subqueryTargetLength != updatedSubqueryEntryCount)
|
||||
{
|
||||
int targetEntryIndex = updatedSubqueryEntryCount;
|
||||
|
||||
for (; targetEntryIndex < subqueryTargetLength; ++targetEntryIndex)
|
||||
{
|
||||
TargetEntry *oldSubqueryTle = list_nth(subquery->targetList,
|
||||
targetEntryIndex);
|
||||
TargetEntry *newSubqueryTargetEntry = copyObject(oldSubqueryTle);
|
||||
TargetEntry *newSubqueryTargetEntry = NULL;
|
||||
|
||||
Assert(newSubqueryTargetEntry->resjunk == true);
|
||||
/*
|
||||
* Skip non-junk entries since we've already processed them above and this
|
||||
* loop only is intended for junk entries.
|
||||
*/
|
||||
if (!oldSubqueryTle->resjunk)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
newSubqueryTargetEntry = copyObject(oldSubqueryTle);
|
||||
|
||||
newSubqueryTargetEntry->resno = resno;
|
||||
newSubqueryTargetlist = lappend(newSubqueryTargetlist,
|
||||
|
@ -2542,7 +2552,6 @@ ReorderInsertSelectTargetLists(Query *originalQuery, RangeTblEntry *insertRte,
|
|||
|
||||
resno++;
|
||||
}
|
||||
}
|
||||
|
||||
originalQuery->targetList = newInsertTargetlist;
|
||||
subquery->targetList = newSubqueryTargetlist;
|
||||
|
|
|
@ -1741,3 +1741,307 @@ DEBUG: Plan is router executable
|
|||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
SET client_min_messages TO INFO;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: ProcessUtility
|
||||
-- some tests with DEFAULT columns and constant values
|
||||
-- this test is mostly importantly intended for deparsing the query correctly
|
||||
-- but still it is preferable to have this test here instead of multi_deparse_shard_query
|
||||
CREATE TABLE table_with_defaults
|
||||
(
|
||||
store_id int,
|
||||
first_name text,
|
||||
default_1 int DEFAULT 1,
|
||||
last_name text,
|
||||
default_2 text DEFAULT '2'
|
||||
);
|
||||
-- we don't need many shards
|
||||
SET citus.shard_count = 2;
|
||||
SELECT create_distributed_table('table_with_defaults', 'store_id');
|
||||
create_distributed_table
|
||||
--------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- let's see the queries
|
||||
SET client_min_messages TO DEBUG4;
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
-- a very simple query
|
||||
INSERT INTO table_with_defaults SELECT * FROM table_with_defaults;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: predicate pruning for shardId 13300014
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300013 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, first_name, default_1, last_name, default_2 FROM public.table_with_defaults_13300013 table_with_defaults WHERE ((hashint4(store_id) >= '-2147483648'::integer) AND (hashint4(store_id) <= '-1'::integer))
|
||||
DEBUG: predicate pruning for shardId 13300013
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300014 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, first_name, default_1, last_name, default_2 FROM public.table_with_defaults_13300014 table_with_defaults WHERE ((hashint4(store_id) >= 0) AND (hashint4(store_id) <= 2147483647))
|
||||
DEBUG: ProcessQuery
|
||||
DEBUG: Plan is router executable
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
-- see that defaults are filled
|
||||
INSERT INTO table_with_defaults (store_id, first_name)
|
||||
SELECT
|
||||
store_id, first_name
|
||||
FROM
|
||||
table_with_defaults;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: predicate pruning for shardId 13300014
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300013 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, first_name, 1 AS default_1, '2'::text AS default_2 FROM public.table_with_defaults_13300013 table_with_defaults WHERE ((hashint4(store_id) >= '-2147483648'::integer) AND (hashint4(store_id) <= '-1'::integer))
|
||||
DEBUG: predicate pruning for shardId 13300013
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300014 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, first_name, 1 AS default_1, '2'::text AS default_2 FROM public.table_with_defaults_13300014 table_with_defaults WHERE ((hashint4(store_id) >= 0) AND (hashint4(store_id) <= 2147483647))
|
||||
DEBUG: ProcessQuery
|
||||
DEBUG: Plan is router executable
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
-- shuffle one of the defaults and skip the other
|
||||
INSERT INTO table_with_defaults (default_2, store_id, first_name)
|
||||
SELECT
|
||||
default_2, store_id, first_name
|
||||
FROM
|
||||
table_with_defaults;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: predicate pruning for shardId 13300014
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300013 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, first_name, 1 AS default_1, default_2 FROM public.table_with_defaults_13300013 table_with_defaults WHERE ((hashint4(store_id) >= '-2147483648'::integer) AND (hashint4(store_id) <= '-1'::integer))
|
||||
DEBUG: predicate pruning for shardId 13300013
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300014 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, first_name, 1 AS default_1, default_2 FROM public.table_with_defaults_13300014 table_with_defaults WHERE ((hashint4(store_id) >= 0) AND (hashint4(store_id) <= 2147483647))
|
||||
DEBUG: ProcessQuery
|
||||
DEBUG: Plan is router executable
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
-- shuffle both defaults
|
||||
INSERT INTO table_with_defaults (default_2, store_id, default_1, first_name)
|
||||
SELECT
|
||||
default_2, store_id, default_1, first_name
|
||||
FROM
|
||||
table_with_defaults;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: predicate pruning for shardId 13300014
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300013 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, first_name, default_1, default_2 FROM public.table_with_defaults_13300013 table_with_defaults WHERE ((hashint4(store_id) >= '-2147483648'::integer) AND (hashint4(store_id) <= '-1'::integer))
|
||||
DEBUG: predicate pruning for shardId 13300013
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300014 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, first_name, default_1, default_2 FROM public.table_with_defaults_13300014 table_with_defaults WHERE ((hashint4(store_id) >= 0) AND (hashint4(store_id) <= 2147483647))
|
||||
DEBUG: ProcessQuery
|
||||
DEBUG: Plan is router executable
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
-- use constants instead of non-default column
|
||||
INSERT INTO table_with_defaults (default_2, last_name, store_id, first_name)
|
||||
SELECT
|
||||
default_2, 'Freund', store_id, 'Andres'
|
||||
FROM
|
||||
table_with_defaults;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: predicate pruning for shardId 13300014
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300013 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, 'Andres'::text AS first_name, 1 AS default_1, 'Freund'::text AS last_name, default_2 FROM public.table_with_defaults_13300013 table_with_defaults WHERE ((hashint4(store_id) >= '-2147483648'::integer) AND (hashint4(store_id) <= '-1'::integer))
|
||||
DEBUG: predicate pruning for shardId 13300013
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300014 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, 'Andres'::text AS first_name, 1 AS default_1, 'Freund'::text AS last_name, default_2 FROM public.table_with_defaults_13300014 table_with_defaults WHERE ((hashint4(store_id) >= 0) AND (hashint4(store_id) <= 2147483647))
|
||||
DEBUG: ProcessQuery
|
||||
DEBUG: Plan is router executable
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
-- use constants instead of non-default column and skip both defauls
|
||||
INSERT INTO table_with_defaults (last_name, store_id, first_name)
|
||||
SELECT
|
||||
'Freund', store_id, 'Andres'
|
||||
FROM
|
||||
table_with_defaults;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: predicate pruning for shardId 13300014
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300013 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, 'Andres'::text AS first_name, 1 AS default_1, 'Freund'::text AS last_name, '2'::text AS default_2 FROM public.table_with_defaults_13300013 table_with_defaults WHERE ((hashint4(store_id) >= '-2147483648'::integer) AND (hashint4(store_id) <= '-1'::integer))
|
||||
DEBUG: predicate pruning for shardId 13300013
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300014 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, 'Andres'::text AS first_name, 1 AS default_1, 'Freund'::text AS last_name, '2'::text AS default_2 FROM public.table_with_defaults_13300014 table_with_defaults WHERE ((hashint4(store_id) >= 0) AND (hashint4(store_id) <= 2147483647))
|
||||
DEBUG: ProcessQuery
|
||||
DEBUG: Plan is router executable
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
-- use constants instead of default columns
|
||||
INSERT INTO table_with_defaults (default_2, last_name, store_id, first_name, default_1)
|
||||
SELECT
|
||||
20, last_name, store_id, first_name, 10
|
||||
FROM
|
||||
table_with_defaults;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: predicate pruning for shardId 13300014
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300013 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, first_name, 10, last_name, 20 FROM public.table_with_defaults_13300013 table_with_defaults WHERE ((hashint4(store_id) >= '-2147483648'::integer) AND (hashint4(store_id) <= '-1'::integer))
|
||||
DEBUG: predicate pruning for shardId 13300013
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300014 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, first_name, 10, last_name, 20 FROM public.table_with_defaults_13300014 table_with_defaults WHERE ((hashint4(store_id) >= 0) AND (hashint4(store_id) <= 2147483647))
|
||||
DEBUG: ProcessQuery
|
||||
DEBUG: Plan is router executable
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
-- use constants instead of both default columns and non-default columns
|
||||
INSERT INTO table_with_defaults (default_2, last_name, store_id, first_name, default_1)
|
||||
SELECT
|
||||
20, 'Freund', store_id, 'Andres', 10
|
||||
FROM
|
||||
table_with_defaults;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: predicate pruning for shardId 13300014
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300013 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, 'Andres'::text AS first_name, 10, 'Freund'::text AS last_name, 20 FROM public.table_with_defaults_13300013 table_with_defaults WHERE ((hashint4(store_id) >= '-2147483648'::integer) AND (hashint4(store_id) <= '-1'::integer))
|
||||
DEBUG: predicate pruning for shardId 13300013
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300014 AS citus_table_alias (store_id, first_name, default_1, last_name, default_2) SELECT store_id, 'Andres'::text AS first_name, 10, 'Freund'::text AS last_name, 20 FROM public.table_with_defaults_13300014 table_with_defaults WHERE ((hashint4(store_id) >= 0) AND (hashint4(store_id) <= 2147483647))
|
||||
DEBUG: ProcessQuery
|
||||
DEBUG: Plan is router executable
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
-- some of the the ultimate queries where we have constants,
|
||||
-- defaults and group by entry is not on the target entry
|
||||
INSERT INTO table_with_defaults (default_2, store_id, first_name)
|
||||
SELECT
|
||||
'2000', store_id, 'Andres'
|
||||
FROM
|
||||
table_with_defaults
|
||||
GROUP BY
|
||||
last_name, store_id;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: predicate pruning for shardId 13300014
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300013 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1 AS default_1, '2000'::text AS default_2 FROM public.table_with_defaults_13300013 table_with_defaults WHERE ((hashint4(store_id) >= '-2147483648'::integer) AND (hashint4(store_id) <= '-1'::integer)) GROUP BY last_name, store_id
|
||||
DEBUG: predicate pruning for shardId 13300013
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300014 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1 AS default_1, '2000'::text AS default_2 FROM public.table_with_defaults_13300014 table_with_defaults WHERE ((hashint4(store_id) >= 0) AND (hashint4(store_id) <= 2147483647)) GROUP BY last_name, store_id
|
||||
DEBUG: ProcessQuery
|
||||
DEBUG: Plan is router executable
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
INSERT INTO table_with_defaults (default_1, store_id, first_name, default_2)
|
||||
SELECT
|
||||
1000, store_id, 'Andres', '2000'
|
||||
FROM
|
||||
table_with_defaults
|
||||
GROUP BY
|
||||
last_name, store_id, first_name;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: predicate pruning for shardId 13300014
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300013 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1000, '2000'::text AS default_2 FROM public.table_with_defaults_13300013 table_with_defaults WHERE ((hashint4(store_id) >= '-2147483648'::integer) AND (hashint4(store_id) <= '-1'::integer)) GROUP BY last_name, store_id, first_name
|
||||
DEBUG: predicate pruning for shardId 13300013
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300014 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1000, '2000'::text AS default_2 FROM public.table_with_defaults_13300014 table_with_defaults WHERE ((hashint4(store_id) >= 0) AND (hashint4(store_id) <= 2147483647)) GROUP BY last_name, store_id, first_name
|
||||
DEBUG: ProcessQuery
|
||||
DEBUG: Plan is router executable
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
INSERT INTO table_with_defaults (default_1, store_id, first_name, default_2)
|
||||
SELECT
|
||||
1000, store_id, 'Andres', '2000'
|
||||
FROM
|
||||
table_with_defaults
|
||||
GROUP BY
|
||||
last_name, store_id, first_name, default_2;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: predicate pruning for shardId 13300014
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300013 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1000, '2000'::text AS default_2 FROM public.table_with_defaults_13300013 table_with_defaults WHERE ((hashint4(store_id) >= '-2147483648'::integer) AND (hashint4(store_id) <= '-1'::integer)) GROUP BY last_name, store_id, first_name, default_2
|
||||
DEBUG: predicate pruning for shardId 13300013
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300014 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1000, '2000'::text AS default_2 FROM public.table_with_defaults_13300014 table_with_defaults WHERE ((hashint4(store_id) >= 0) AND (hashint4(store_id) <= 2147483647)) GROUP BY last_name, store_id, first_name, default_2
|
||||
DEBUG: ProcessQuery
|
||||
DEBUG: Plan is router executable
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
INSERT INTO table_with_defaults (default_1, store_id, first_name)
|
||||
SELECT
|
||||
1000, store_id, 'Andres'
|
||||
FROM
|
||||
table_with_defaults
|
||||
GROUP BY
|
||||
last_name, store_id, first_name, default_2;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: predicate pruning for shardId 13300014
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300013 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1000, '2'::text AS default_2 FROM public.table_with_defaults_13300013 table_with_defaults WHERE ((hashint4(store_id) >= '-2147483648'::integer) AND (hashint4(store_id) <= '-1'::integer)) GROUP BY last_name, store_id, first_name, default_2
|
||||
DEBUG: predicate pruning for shardId 13300013
|
||||
DEBUG: distributed statement: INSERT INTO public.table_with_defaults_13300014 AS citus_table_alias (store_id, first_name, default_1, default_2) SELECT store_id, 'Andres'::text AS first_name, 1000, '2'::text AS default_2 FROM public.table_with_defaults_13300014 table_with_defaults WHERE ((hashint4(store_id) >= 0) AND (hashint4(store_id) <= 2147483647)) GROUP BY last_name, store_id, first_name, default_2
|
||||
DEBUG: ProcessQuery
|
||||
DEBUG: Plan is router executable
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300013
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
DEBUG: sent COMMIT over connection 13300014
|
||||
-- set back to the default
|
||||
SET citus.shard_count TO DEFAULT;
|
||||
DEBUG: StartTransactionCommand
|
||||
DEBUG: StartTransaction
|
||||
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
DEBUG: ProcessUtility
|
||||
DEBUG: CommitTransactionCommand
|
||||
DEBUG: CommitTransaction
|
||||
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
|
||||
|
|
|
@ -715,3 +715,114 @@ SET client_min_messages TO DEBUG4;
|
|||
|
||||
-- this should also work
|
||||
INSERT INTO raw_events_first SELECT * FROM raw_events_second WHERE user_id = 5;
|
||||
|
||||
|
||||
SET client_min_messages TO INFO;
|
||||
-- some tests with DEFAULT columns and constant values
|
||||
-- this test is mostly importantly intended for deparsing the query correctly
|
||||
-- but still it is preferable to have this test here instead of multi_deparse_shard_query
|
||||
CREATE TABLE table_with_defaults
|
||||
(
|
||||
store_id int,
|
||||
first_name text,
|
||||
default_1 int DEFAULT 1,
|
||||
last_name text,
|
||||
default_2 text DEFAULT '2'
|
||||
);
|
||||
|
||||
-- we don't need many shards
|
||||
SET citus.shard_count = 2;
|
||||
SELECT create_distributed_table('table_with_defaults', 'store_id');
|
||||
|
||||
-- let's see the queries
|
||||
SET client_min_messages TO DEBUG4;
|
||||
|
||||
-- a very simple query
|
||||
INSERT INTO table_with_defaults SELECT * FROM table_with_defaults;
|
||||
|
||||
-- see that defaults are filled
|
||||
INSERT INTO table_with_defaults (store_id, first_name)
|
||||
SELECT
|
||||
store_id, first_name
|
||||
FROM
|
||||
table_with_defaults;
|
||||
|
||||
-- shuffle one of the defaults and skip the other
|
||||
INSERT INTO table_with_defaults (default_2, store_id, first_name)
|
||||
SELECT
|
||||
default_2, store_id, first_name
|
||||
FROM
|
||||
table_with_defaults;
|
||||
|
||||
-- shuffle both defaults
|
||||
INSERT INTO table_with_defaults (default_2, store_id, default_1, first_name)
|
||||
SELECT
|
||||
default_2, store_id, default_1, first_name
|
||||
FROM
|
||||
table_with_defaults;
|
||||
|
||||
-- use constants instead of non-default column
|
||||
INSERT INTO table_with_defaults (default_2, last_name, store_id, first_name)
|
||||
SELECT
|
||||
default_2, 'Freund', store_id, 'Andres'
|
||||
FROM
|
||||
table_with_defaults;
|
||||
|
||||
-- use constants instead of non-default column and skip both defauls
|
||||
INSERT INTO table_with_defaults (last_name, store_id, first_name)
|
||||
SELECT
|
||||
'Freund', store_id, 'Andres'
|
||||
FROM
|
||||
table_with_defaults;
|
||||
|
||||
-- use constants instead of default columns
|
||||
INSERT INTO table_with_defaults (default_2, last_name, store_id, first_name, default_1)
|
||||
SELECT
|
||||
20, last_name, store_id, first_name, 10
|
||||
FROM
|
||||
table_with_defaults;
|
||||
|
||||
-- use constants instead of both default columns and non-default columns
|
||||
INSERT INTO table_with_defaults (default_2, last_name, store_id, first_name, default_1)
|
||||
SELECT
|
||||
20, 'Freund', store_id, 'Andres', 10
|
||||
FROM
|
||||
table_with_defaults;
|
||||
|
||||
-- some of the the ultimate queries where we have constants,
|
||||
-- defaults and group by entry is not on the target entry
|
||||
INSERT INTO table_with_defaults (default_2, store_id, first_name)
|
||||
SELECT
|
||||
'2000', store_id, 'Andres'
|
||||
FROM
|
||||
table_with_defaults
|
||||
GROUP BY
|
||||
last_name, store_id;
|
||||
|
||||
INSERT INTO table_with_defaults (default_1, store_id, first_name, default_2)
|
||||
SELECT
|
||||
1000, store_id, 'Andres', '2000'
|
||||
FROM
|
||||
table_with_defaults
|
||||
GROUP BY
|
||||
last_name, store_id, first_name;
|
||||
|
||||
|
||||
INSERT INTO table_with_defaults (default_1, store_id, first_name, default_2)
|
||||
SELECT
|
||||
1000, store_id, 'Andres', '2000'
|
||||
FROM
|
||||
table_with_defaults
|
||||
GROUP BY
|
||||
last_name, store_id, first_name, default_2;
|
||||
|
||||
INSERT INTO table_with_defaults (default_1, store_id, first_name)
|
||||
SELECT
|
||||
1000, store_id, 'Andres'
|
||||
FROM
|
||||
table_with_defaults
|
||||
GROUP BY
|
||||
last_name, store_id, first_name, default_2;
|
||||
|
||||
-- set back to the default
|
||||
SET citus.shard_count TO DEFAULT;
|
||||
|
|
Loading…
Reference in New Issue