Repository: citusdata/citus

Issue #6392: Cache lookup failure after dropping type used in partition column
Created: 2022-10-03T14:05:33Z
What we fail to access is the distribution column and its type, because it is dropped from previous DROP TYPE comp_type CASCADE. The issue can be reproduced as follows:
SET citus.shard_count TO 4;

CREATE TYPE my_type AS (int_field int);
CREATE TABLE tbl (a my_type);
SELECT create_distributed_table('tbl', 'a');

-- the following should error out but it doesn't
-- it drops the distribution column of the table in the coordinator -- OOPS!
-- doesn't propagate anything to shards
DROP TYPE my_type CASCADE;
NOTICE:  drop cascades to column a of table tbl

-- OOPS no distribution column
\d+ tbl
               Table "public.tbl"
 Column | Type | Collation | Nullable | Default
--------+------+-----------+----------+---------

-- shards are still there!!
SELECT run_command_on_workers($$ SELECT json_agg(relname) FROM pg_class WHERE relname LIKE 'tbl%'$$);
                     run_command_on_workers
----------------------------------------------------------------
 (localhost,9701,t,"[""tbl"", ""tbl_102008"", ""tbl_102010""]")
 (localhost,9702,t,"[""tbl"", ""tbl_102009"", ""tbl_102011""]")
(2 rows)

SELECT * FROM citus_shards;
ERROR:  cache lookup failed for type 17132

DROP TABLE tbl;
ERROR:  cache lookup failed for type 17132
EDIT: problem already mentioned in citusdata/citus-enterprise#687
Originally posted by @naisila in #5780 (comment)

Duplicate issue #7886: Dropping a custom data type used as partition key cause problems
Created: 2025-02-05T12:55:13Z
It is possible to drop a data type that is used as a distribution key by citus.
However, as the datatype is still stored by citus, querying the corresponding table and citus_table fails,
See the logs below.
A possible solution is to avoid dropping a data when it is used as a distribution key. An alternative would be propagating the drop operation to citus internal tables (need further analysis)
ebru=# create type my_type AS (d1 int, d2 int);
CREATE TYPE
ebru=# create table test_table(data my_type, id int);
CREATE TABLE
ebru=# select create_distributed_table('test_table', 'data');
 create_distributed_table
--------------------------

(1 row)

ebru=#
ebru=# drop type my_type ;
ERROR:  cannot drop type my_type because other objects depend on it
DETAIL:  column data of table test_table depends on type my_type
HINT:  Use DROP ... CASCADE to drop the dependent objects too.
ebru=# drop type my_type cascade;
NOTICE:  drop cascades to column data of table test_table
DROP TYPE
ebru=#
ebru=# select * from test_table ;
ERROR:  cache lookup failed for type 17275
ebru=# select * from citus_tables ;
ERROR:  cache lookup failed for type 17275
ebru=#
ebru=# select * from pg_dist_colocation;
 colocationid | shardcount | replicationfactor | distributioncolumntype | distributioncolumncollation
--------------+------------+-------------------+------------------------+-----------------------------
            1 |         32 |                 1 |                  17275 |                           0
            2 |         32 |                 1 |                     23 |                           0
(2 rows)

Closing comment (2025-02-10T11:50:26Z): Same as #6392, so I'm closing this one.