insert into <reference table> select from <another reference table> fails with permission error
- Dominant language
- C
- Stars
- 12.8k
- Forks
- 794
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 31
Description
it requires 2 users, and 2 reference tables to reproduce.
Following repro is created on Azure Cosmos DB for PostgreSQL cluster with 2 worker nodes.
First create a schemas and source tables with `citus` user
```sql
-- citus user
create schema etl;
grant usage on schema etl to testread;
create table etl.videos(videoid bigint, lengthinseconds int);
select create_reference_table('etl.videos');
insert into etl.videos select (random() * 10000)::BIGINT, (random() * 1000)::int from generate_series(1, 1000000);
GRANT select ON table etl.videos TO testread;
create schema summary;
GRANT ALL ON SCHEMA summary TO testread;
```
Then switch to other user `testread`
```sql
---- testread user
CREATE TABLE summary.small_videos ( videoid bigint );
select create_reference_table('summary.small_videos');
-- verify simple select query works
SELECT DISTINCT vids.videoid
FROM etl.videos vids
WHERE ((vids.lengthinseconds <= 10)) LIMIT 1;
-- then test run insert
INSERT INTO summary.small_videos (videoid)
SELECT DISTINCT vids.videoid
FROM etl.videos vids
WHERE ((vids.lengthinseconds <= 10)) LIMIT 1;
```
it fails with
```
ERROR: permission denied for table videos
CONTEXT: while executing command on :5432
```
Examining worker logs revealed that worker query fails while running `lock_shard_resources` on `etl.videos` table with lockmode = 7
There is a workaround to use CTEs like
```sql
WITH test_data AS (SELECT DISTINCT vids.videoid
FROM etl.videos vids
WHERE ((vids.lengthinseconds <= 10)) limit 1)
INSERT INTO summary.small_videos select * FROM test_data
```
PG Version : PG 16.9
Citus Version : 12.1.6
Contributor guide
Assessment
This issue has not been assessed yet.