1--
2-- MULTI_REPARTITION_JOIN_TASK_ASSIGNMENT
3--
4-- Tests which cover task assignment for MapMerge jobs for single range repartition
5-- and dual hash repartition joins. The tests also cover task assignment propagation
6-- from a sql task to its dependent tasks. Note that we set the executor type to task
7-- tracker executor here, as we cannot run repartition jobs with real time executor.
8SET citus.next_shard_id TO 710000;
9BEGIN;
10SET client_min_messages TO DEBUG3;
11SET citus.enable_repartition_joins to ON;
12-- Single range repartition join to test anchor-shard based task assignment and
13-- assignment propagation to merge and data-fetch tasks.
14SELECT
15	count(*)
16FROM
17	orders, customer_append
18WHERE
19	o_custkey = c_custkey;
20DEBUG:  Router planner does not support append-partitioned tables.
21DEBUG:  no sharding pruning constraints on orders found
22DEBUG:  shard count after pruning for orders: 2
23DEBUG:  assigned task to node localhost:xxxxx
24DEBUG:  assigned task to node localhost:xxxxx
25DEBUG:  no sharding pruning constraints on customer_append found
26DEBUG:  shard count after pruning for customer_append: 3
27DEBUG:  join prunable for intervals [1,1000] and [1001,2000]
28DEBUG:  join prunable for intervals [1,1000] and [6001,7000]
29DEBUG:  join prunable for intervals [1001,2000] and [1,1000]
30DEBUG:  join prunable for intervals [1001,2000] and [6001,7000]
31DEBUG:  join prunable for intervals [6001,7000] and [1,1000]
32DEBUG:  join prunable for intervals [6001,7000] and [1001,2000]
33DEBUG:  pruning merge fetch taskId 1
34DETAIL:  Creating dependency on merge taskId 3
35DEBUG:  pruning merge fetch taskId 3
36DETAIL:  Creating dependency on merge taskId 6
37DEBUG:  pruning merge fetch taskId 5
38DETAIL:  Creating dependency on merge taskId 9
39DEBUG:  assigned task to node localhost:xxxxx
40DEBUG:  assigned task to node localhost:xxxxx
41DEBUG:  assigned task to node localhost:xxxxx
42 count
43---------------------------------------------------------------------
44  2985
45(1 row)
46
47-- Single range repartition join, along with a join with a small table containing
48-- more than one shard. This situation results in multiple sql tasks depending on
49-- the same merge task, and tests our constraint group creation and assignment
50-- propagation.
51SELECT
52	count(*)
53FROM
54	orders_reference, customer_append, lineitem
55WHERE
56	o_custkey = c_custkey AND
57	o_orderkey = l_orderkey;
58DEBUG:  Router planner does not support append-partitioned tables.
59DEBUG:  no sharding pruning constraints on customer_append found
60DEBUG:  shard count after pruning for customer_append: 3
61DEBUG:  assigned task to node localhost:xxxxx
62DEBUG:  assigned task to node localhost:xxxxx
63DEBUG:  assigned task to node localhost:xxxxx
64DEBUG:  no sharding pruning constraints on lineitem found
65DEBUG:  shard count after pruning for lineitem: 2
66DEBUG:  join prunable for intervals [1,5986] and [8997,14947]
67DEBUG:  join prunable for intervals [8997,14947] and [1,5986]
68DEBUG:  pruning merge fetch taskId 1
69DETAIL:  Creating dependency on merge taskId 4
70DEBUG:  pruning merge fetch taskId 3
71DETAIL:  Creating dependency on merge taskId 8
72DEBUG:  assigned task to node localhost:xxxxx
73DEBUG:  assigned task to node localhost:xxxxx
74 count
75---------------------------------------------------------------------
76 12000
77(1 row)
78
79-- Dual hash repartition join which tests the separate hash repartition join
80-- task assignment algorithm.
81SELECT
82	count(*)
83FROM
84	lineitem, customer_append
85WHERE
86	l_partkey = c_nationkey;
87DEBUG:  Router planner does not support append-partitioned tables.
88DEBUG:  no sharding pruning constraints on lineitem found
89DEBUG:  shard count after pruning for lineitem: 2
90DEBUG:  assigned task to node localhost:xxxxx
91DEBUG:  assigned task to node localhost:xxxxx
92DEBUG:  no sharding pruning constraints on customer_append found
93DEBUG:  shard count after pruning for customer_append: 3
94DEBUG:  assigned task to node localhost:xxxxx
95DEBUG:  assigned task to node localhost:xxxxx
96DEBUG:  assigned task to node localhost:xxxxx
97DEBUG:  join prunable for task partitionId 0 and 1
98DEBUG:  join prunable for task partitionId 0 and 2
99DEBUG:  join prunable for task partitionId 0 and 3
100DEBUG:  join prunable for task partitionId 1 and 0
101DEBUG:  join prunable for task partitionId 1 and 2
102DEBUG:  join prunable for task partitionId 1 and 3
103DEBUG:  join prunable for task partitionId 2 and 0
104DEBUG:  join prunable for task partitionId 2 and 1
105DEBUG:  join prunable for task partitionId 2 and 3
106DEBUG:  join prunable for task partitionId 3 and 0
107DEBUG:  join prunable for task partitionId 3 and 1
108DEBUG:  join prunable for task partitionId 3 and 2
109DEBUG:  pruning merge fetch taskId 1
110DETAIL:  Creating dependency on merge taskId 3
111DEBUG:  pruning merge fetch taskId 2
112DETAIL:  Creating dependency on merge taskId 4
113DEBUG:  pruning merge fetch taskId 4
114DETAIL:  Creating dependency on merge taskId 6
115DEBUG:  pruning merge fetch taskId 5
116DETAIL:  Creating dependency on merge taskId 8
117DEBUG:  pruning merge fetch taskId 7
118DETAIL:  Creating dependency on merge taskId 9
119DEBUG:  pruning merge fetch taskId 8
120DETAIL:  Creating dependency on merge taskId 12
121DEBUG:  pruning merge fetch taskId 10
122DETAIL:  Creating dependency on merge taskId 12
123DEBUG:  pruning merge fetch taskId 11
124DETAIL:  Creating dependency on merge taskId 16
125DEBUG:  assigned task to node localhost:xxxxx
126DEBUG:  assigned task to node localhost:xxxxx
127DEBUG:  assigned task to node localhost:xxxxx
128DEBUG:  assigned task to node localhost:xxxxx
129 count
130---------------------------------------------------------------------
131   125
132(1 row)
133
134-- Reset client logging level to its previous value
135SET client_min_messages TO NOTICE;
136COMMIT;
137