create_time_partitions may fail with long table names
SET citus.shard_replication_factor TO 2;
CREATE TABLE
time_series_events_very_veery_looooooooooooooong_named_table (event_time timestamp, event int, user_id int)
partition by range (event_time);
SELECT create_distributed_table('time_series_events_very_veery_looooooooooooooong_named_table', 'user_id');
SELECT create_time_partitions(table_name:='time_series_events_very_veery_looooooooooooooong_named_table',
partition_interval:= '1 month',
end_at:= '2021-01-01',
start_from:='2020-01-01');
ERROR: could not form array type name for type "time_series_events_very_veery_looooooooooooooon_b7a98e08_108896"
CONTEXT: while executing command on localhost:9701
SQL statement "CREATE TABLE public.time_series_events_very_veery_looooooooooooooong_named_p2020_09 PARTITION OF public.time_series_events_very_veery_looooooooooooooong_named_table FOR VALUES FROM ('2020-09-01 00:00:00') TO ('2020-10-01 00:00:00')"
PL/pgSQL function create_time_partitions(regclass,interval,timestamp with time zone,timestamp with time zone) line 28 at EXECUTE
Time: 481.143 ms
@velioglu reproduced this with rep == 1, so this is more important now
It happens because with the new create_time_partitions UDF it is easy to create lots of partitions which have first 47 char in common. I've explained the root cause below.
PG creates array type name for each table by prepending _ at the beginning of the table. If PG finds any type with the same name, it continues by adding more _s. If type's name length becomes more than 63, PG basically drops the last character(s).
It becomes problematic since shard names' length is 63. While trying to prepend _ at the beginning, PG drops the latest char for the first shard. Then, for the upcoming shard name for the same partition (shard names can be sth like time_series_events_very_veery_looooooooooooooon_b31af63f_102315 and time_series_events_very_veery_looooooooooooooon_b31af63f_102316 for the shards of the same partition) PG needs to drop last 2 chars as the name _time_series_events_very_veery_looooooooooooooon_b31af63f_10231 has already been used for the first shard. Then it continues till the name becomes whole underscores. And finally PG errors out because it can not find a new name within the name length limit.
As a workaround one can alter the name of the parent table to a sth with less characters like
ALTER TABLE time_series_events_very_veery_looooooooooooooong_named_table RENAME TO short_table_name;
All time partition management utility functions create_time_partitions, alter_old_partitions_set_access_method and drop_old_time_partitions will work with the new table name.
Could be resolved via https://www.postgresql.org/message-id/flat/CACawEhWxE3V4L7zU1XD03pO2D7pRUATsmeU2x8C4uYCd4y%3DUaw%40mail.gmail.com#5167047df7ca0b8bdae9ea3847b8f689