Skip to content

sql: allow SHOW RANGE FROM TABLE foo FOR ROW to only apply for fields in PK #41421

@awoods187

Description

@awoods187

Using the new SQL SHOW RANGE FROM TABLE foo FOR ROW command is a bit difficult as it requires the user to input some values for all of the columns in the table and not just the PK:
Consider the vehicles table in MovR:

show create table vehicles;
  table_name |                                       create_statement
+------------+-----------------------------------------------------------------------------------------------+
  vehicles   | CREATE TABLE vehicles (
             |     id UUID NOT NULL,
             |     city VARCHAR NOT NULL,
             |     type VARCHAR NULL,
             |     owner_id UUID NULL,
             |     creation_time TIMESTAMP NULL,
             |     status VARCHAR NULL,
             |     current_location VARCHAR NULL,
             |     ext JSONB NULL,
             |     CONSTRAINT "primary" PRIMARY KEY (city ASC, id ASC),
             |     CONSTRAINT fk_city_ref_users FOREIGN KEY (city, owner_id) REFERENCES users(city, id),
             |     INDEX vehicles_auto_index_fk_city_ref_users (city ASC, owner_id ASC),
             |     FAMILY "primary" (id, city, type, owner_id, creation_time, status, current_location, ext)
             | )
(1 row)

Time: 46.349ms

To use the new command you must provide values for every entry and not just those in the PK:

show range from table vehicles for row ('acde070d-8c4c-4f0d-9d8a-162843c10333','san francisco','',Null,Null,'','',Null);
  start_key | end_key | range_id | lease_holder | lease_holder_locality | replicas |                           replica_localities
+-----------+---------+----------+--------------+-----------------------+----------+------------------------------------------------------------------------+
  NULL      | NULL    |       26 |            4 | region=us-east,az=1   | {3,4,8}  | {"region=us-west,az=2","region=us-east,az=1","region=us-central,az=1"}
(1 row)

Time: 7.347ms

PK only:

root@127.0.0.1:49818/movr> show range from table vehicles for row ('acde070d-8c4c-4f0d-9d8a-162843c10333','san francisco');
pq: number of values in row must equal number of columns in the requested table

You must provide values for everything in a secondary index which means, in effect, you must provide values for all columns in order to specify which columns apply.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)S-3-ux-surpriseIssue leaves users wondering whether CRDB is behaving properly. Likely to hurt reputation/adoption.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions