Skip to content

INSERT ... SELECT ... between schema based sharding tables incorrectly without erroring out #8243

@buriedpot

Description

@buriedpot

Environment

PG 16 + Citus 12.1.5

Prepare

CREATE SCHEMA my_test;
SELECT citus_schema_distribute('my_test');
SET search_path TO my_test;
CREATE TABLE t1(id bigserial PRIMARY KEY, name text);
CREATE TABLE t2(id bigserial PRIMARY KEY, name text);

Error

=> EXPLAIN INSERT INTO my_test.t1(name) SELECT name FROM (SELECT name, max(id) FROM my_test.t2 GROUP BY name) AS sub;
                                     QUERY PLAN                                      
-----------------------------------------------
 Custom Scan (Citus INSERT ... SELECT)  (cost=0.00..0.00 rows=0 width=0)
   INSERT/SELECT method: pull to coordinator
   ->  Custom Scan (Citus Adaptive)  (cost=0.00..250.00 rows=100000 width=40)
         Task Count: 0
         Tasks Shown: All
(5 rows)

Here, Task Count: 0 is not expected.

Analysis

The reason may be related to the following code. It doesn't handle schema based sharding tables and doesn't error out.

multi_physical_planner.c:2202

	forboth_ptr(prunedShardList, prunedRelationShardList,
				relationRestriction, relationRestrictionContext->relationRestrictionList)
	{
		Oid relationId = relationRestriction->relationId;

		CitusTableCacheEntry *cacheEntry = GetCitusTableCacheEntry(relationId);
		if (!HasDistributionKeyCacheEntry(cacheEntry))
		{
			continue;
		}

Can you review this issue

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions