Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: crdb_internal.ranges{,no_leases} does not interoperate correctly with user-defined schemas #59601

Closed
jordanlewis opened this issue Jan 29, 2021 · 1 comment · Fixed by #59865
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Comments

@jordanlewis
Copy link
Member

There is no disambiguating schema_name column in these tables, but there should be. The consequence of the lack of this is as follows:

demo@127.0.0.1:26257/defaultdb> create schema s;
CREATE SCHEMA

Time: 23ms total (execution 8ms / network 14ms)

demo@127.0.0.1:26257/defaultdb> create table t1 (a) as select 1;
CREATE TABLE AS

Time: 35ms total (execution 4ms / network 31ms)

demo@127.0.0.1:26257/defaultdb> create table s.t1 (a) as select 1;
CREATE TABLE AS

Time: 27ms total (execution 3ms / network 24ms)

demo@127.0.0.1:26257/defaultdb>
demo@127.0.0.1:26257/defaultdb>
demo@127.0.0.1:26257/defaultdb>
demo@127.0.0.1:26257/defaultdb> select * from crdb_Internal.ranges_no_leases where table_name='t1' and database_name='defaultdb';
  range_id | start_key | start_pretty | end_key  | end_pretty | database_name | table_name | index_name | replicas |    replica_localities    | learner_replicas | split_enforced_until
-----------+-----------+--------------+----------+------------+---------------+------------+------------+----------+--------------------------+------------------+-----------------------
        38 | \277      | /Table/55    | \300     | /Table/56  | defaultdb     | t1         |            | {1}      | {"region=us-east1,az=b"} | {}               | NULL
        39 | \300      | /Table/56    | \377\377 | /Max       | defaultdb     | t1         |            | {1}      | {"region=us-east1,az=b"} | {}               | NULL
(2 rows)

In addition, I feel like this table should also contain a table id - it'll just make things easier to join against other tables.

@jordanlewis jordanlewis added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Jan 29, 2021
@jordanlewis
Copy link
Member Author

In fact, if we included the table id, we could implement an efficient virtual index on this table, which would obviate the need to collect all descriptors just to get the range information for a single table, which I think is relatively common.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant