Skip to content

sql: CRDB improperly evaluates certain requests when no database is set #23028

@rytaft

Description

@rytaft

This issue contains 3 separate issues that are all symptoms of the same problem


When no database is set, if I update the search path to include the virtual schemas, selecting from an unqualified table name (that is present in one of the virtual schemas) combines results from all databases.

For example:

root@:26257/> select count(*) from pg_catalog.pg_tables;
+-------+
| count |
+-------+
|   431 |
+-------+
(1 row)

Time: 1.971ms

root@:26257/> select count(*) from t.pg_catalog.pg_tables;
+-------+
| count |
+-------+
|    90 |
+-------+
(1 row)

Time: 1.78ms

It's confusing / surprising that it is possible to see all tables across all physical DBs listed in the virtual tables, but meanwhile one cannot do select * from t if t exists in every database and there is no "current database" set. The intuition given by the vtables would be that "no database set = consider all databases", but name resolution for individual queries do not do this.


regclass gets confused when no database is set, while selection does not:

root@:26257/> select 'public.public.tables'::regclass;
pq: more than one relation named 'tables'
root@:26257/> select 'public.tables'::regclass;
pq: more than one relation named 'tables'
root@:26257/> select * from public.tables;
+----------+-----------+-----------+
| table_id | table_id2 | table_id3 |
+----------+-----------+-----------+
|        4 |         3 |         2 |
|        5 |         5 |         5 |
|        5 |         5 |         5 |
|        5 |         5 |         5 |
+----------+-----------+-----------+
(4 rows)

Time: 1.573ms

REGPROC also doesn't work when no database is set:

root@:26257/> select 'upper'::REGPROC;
pq: more than one function named 'upper'
root@:26257/> select 't.pg_catalog.upper'::REGPROC;
pq: more than one function named 'upper'

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions