With citus_set_coordinator_host(), EXPLAIN (INSERT ... INTO SELECT ... FROM t1 INNER JOIN t1.col = t2.col) shows increased number of merge task count.
- Dominant language
- C
- Stars
- 12.8k
- Forks
- 794
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 31
Description
Changing the regress tests with only adding the coordinator to metadata, I see test result diffs in` multi_insert_select.sql`. Upon further investigation, it turns out that `MapMergeJob `types of jobs has more merge tasks when we add an active node even if it cannot have shards (When we add the coordinator in metadata via `citus_set_coordinator_host` it has the property `shouldhaveshards = false` by default.)
A local repro goes like this:
```
SET citus.next_shard_id TO 13300000;
SET citus.next_placement_id TO 13300000;
SET citus.shard_count = 4;
CREATE TABLE raw_events_first (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint, UNIQUE(user_id, value_1));
SELECT create_distributed_table('raw_events_first', 'user_id');
CREATE TABLE raw_events_second (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint, UNIQUE(user_id, value_1));
SELECT create_distributed_table('raw_events_second', 'user_id');
CREATE TABLE agg_events (user_id int, value_1_agg int, value_2_agg int, value_3_agg float, value_4_agg bigint, agg_time timestamp, UNIQUE(user_id, value_1_agg));
SELECT create_distributed_table('agg_events', 'user_id');;
INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES
(1, now(), 10, 100, 1000.1, 10000);
INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES
(2, now(), 20, 200, 2000.1, 20000);
INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES
(3, now(), 30, 300, 3000.1, 30000);
INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES
(4, now(), 40, 400, 4000.1, 40000);
INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES
(5, now(), 50, 500, 5000.1, 50000);
INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES
(6, now(), 60, 600, 6000.1, 60000);
INSERT INTO raw_events_second (user_id, time)
SELECT
user_id, now()
FROM
raw_events_first
WHERE
user_id < 0;
SET citus.enable_repartition_joins TO true;
EXPLAIN (costs off)
INSERT INTO agg_events (user_id)
SELECT
raw_events_first.user_id
FROM
raw_events_first INNER JOIN raw_events_second ON raw_events_first.value_1 = raw_events_second.value_1;
QUERY PLAN
-------------------------------------------------------------------
Custom Scan (Citus INSERT ... SELECT)
INSERT/SELECT method: pull to coordinator
-> Custom Scan (Citus Adaptive)
Task Count: 8
Tasks Shown: None, not supported for re-partition queries
-> MapMergeJob
Map Task Count: 4
Merge Task Count: 8 <---------------------
-> MapMergeJob
Map Task Count: 4
Merge Task Count: 8 <----------------------
(11 rows)
```
Now add the coordinator and run the EXPLAIN again:
```
select citus_set_coordinator_host('localhost', 9700);
EXPLAIN (costs off)
INSERT INTO agg_events (user_id)
SELECT
raw_events_first.user_id
FROM
raw_events_first INNER JOIN raw_events_second ON raw_events_first.value_1 = raw_events_second.value_1;
QUERY PLAN
-------------------------------------------------------------------
Custom Scan (Citus INSERT ... SELECT)
INSERT/SELECT method: pull to coordinator
-> Custom Scan (Citus Adaptive)
Task Count: 12
Tasks Shown: None, not supported for re-partition queries
-> MapMergeJob
Map Task Count: 4
Merge Task Count: 12 <----------------
-> MapMergeJob
Map Task Count: 4
Merge Task Count: 12 <------------------
```
The additional merge tasks seems like no-op eventually even if we run them which I am not sure. But if this seems wrong I will debug it further.
The culprit in the code is:
```
static MapMergeJob *,
BuildMapMergeJob(Query *jobQuery, List *dependentJobList, Var *partitionKey,
PartitionType partitionType, Oid baseRelationId,
BoundaryNodeJobType boundaryNodeJobType)
{
...
if (partitionType == DUAL_HASH_PARTITION_TYPE)
{
uint32 partitionCount = HashPartitionCount(); <----------------
....
```
```
static uint32,
HashPartitionCount(void)
{
uint32 groupCount = list_length(ActiveReadableNodeList()); <--------- essentially returns (active_node_count x shard count)
```
Contributor guide
Assessment
This issue has not been assessed yet.