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,cli: \d metacommand should not show indexes by default #123946

Closed
rafiss opened this issue May 10, 2024 · 1 comment · Fixed by #124007
Closed

sql,cli: \d metacommand should not show indexes by default #123946

rafiss opened this issue May 10, 2024 · 1 comment · Fixed by #124007
Labels
A-cli-client CLI commands that pertain to using SQL features A-sql-pgcompat Semantic compatibility with PostgreSQL C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. E-easy Easy issue to tackle, requires little or no CockroachDB experience E-starter Might be suitable for a starter project for new employees or team members. good first issue T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@rafiss
Copy link
Collaborator

rafiss commented May 10, 2024

Describe the problem

In psql, the \d metacommand does not show indexes, but in cockroach sql, it does.

From the psql documentation:

If \d is used without a pattern argument, it is equivalent to \dtvmsE which will show a list of all visible tables, views, materialized views, sequences and foreign tables. This is purely a convenience measure.

cockroach sql appears to treat it as \dtivmsE instead.

To Reproduce

Setup with:

create table tbl(a int primary key, b int, index (b));

With PSQL

defaultdb=> \d
                List of relations
    Schema    |       Name        | Type  | Owner
--------------+-------------------+-------+-------
 pg_extension | geography_columns | table | node
 pg_extension | geometry_columns  | table | node
 pg_extension | spatial_ref_sys   | table | node
 public       | tbl               | table | root
(4 rows)

With Cockroach SQL

root@localhost:26257/defaultdb> \d
List of relations:
 Schema |   Name    | Type  | Owner | Table
---------+-----------+-------+-------+--------
 public | tbl       | table | root  | NULL
 public | tbl_b_idx | index | root  | tbl
 public | tbl_pkey  | index | root  | tbl
(3 rows)

Expected behavior
Only tbl should appear in the results. (Postgres also shows some tables from pg_extension, but let's ignore those for now.)

Additional data / screenshots
I captured the queries that were running.

In psql:

SELECT n.nspname as "Schema",
  c.relname as "Name",
  CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 't' THEN 'TOAST table' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' WHEN 'I' THEN 'partitioned index' END as "Type",
  pg_catalog.pg_get_userbyid(c.relowner) as "Owner"
FROM pg_catalog.pg_class c
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
     LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam
WHERE c.relkind IN ('r','p','v','m','S','f','')
      AND n.nspname <> 'pg_catalog'
      AND n.nspname !~ '^pg_toast'
      AND n.nspname <> 'information_schema'
  AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;

In cockroach sql:

   SELECT n.nspname as "Schema",
          c.relname as "Name",
          CASE c.relkind
          WHEN 'r' THEN 'table'
          WHEN 'v' THEN 'view'
          WHEN 'm' THEN 'materialized view'
          WHEN 'i' THEN 'index'
          WHEN 'S' THEN 'sequence'
          WHEN 's' THEN 'special'
          WHEN 't' THEN 'TOAST table'
          WHEN 'f' THEN 'foreign table'
          WHEN 'p' THEN 'partitioned table'
          WHEN 'I' THEN 'partitioned index'
          END as "Type",
          pg_catalog.pg_get_userbyid(c.relowner) as "Owner",
          c2.relname AS "Table"
     FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n on n.oid = c.relnamespace
LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam
LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid
LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid
    WHERE c.relkind IN ('r','p','v','m','i','S','f','')
      AND n.nspname !~ '^pg_'
      AND n.nspname <> 'information_schema'
      AND n.nspname <> 'crdb_internal'
      AND pg_catalog.pg_table_is_visible(c.oid)
 ORDER BY 1,2

Additional context
See slack thread: https://cockroachlabs.slack.com/archives/C0168LW5THS/p1715331247139219

Jira issue: CRDB-38618

@rafiss rafiss added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. E-easy Easy issue to tackle, requires little or no CockroachDB experience good first issue E-starter Might be suitable for a starter project for new employees or team members. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) A-cli-client CLI commands that pertain to using SQL features labels May 10, 2024
@blathers-crl blathers-crl bot added this to Triage in SQL Foundations May 10, 2024
@rafiss rafiss added the A-sql-pgcompat Semantic compatibility with PostgreSQL label May 10, 2024
@sean-
Copy link
Collaborator

sean- commented May 10, 2024

This has always been a UX surprise, and there's no good reason that I can think of why we wouldn't want to be compatible with PostgreSQL. The muscle memory runs deep.

craig bot pushed a commit that referenced this issue May 13, 2024
124007: clisqlshell: fix `\d` metacommand to exclude indexes by default. r=rafiss a=miyamo2

This commit makes the `\d` metacommand in the `cockroach sql` excludes indexes by default to align with `psql` behavior. This ensures that only tables, views, materialized views, sequences, foreign tables and partitioned table are showed by default.

Fixes #123946

Release note: None

Co-authored-by: miyamo2 <79917704+miyamo2@users.noreply.github.com>
@craig craig bot closed this as completed in 664124b May 13, 2024
SQL Foundations automation moved this from Triage to Done May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli-client CLI commands that pertain to using SQL features A-sql-pgcompat Semantic compatibility with PostgreSQL C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. E-easy Easy issue to tackle, requires little or no CockroachDB experience E-starter Might be suitable for a starter project for new employees or team members. good first issue T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
Development

Successfully merging a pull request may close this issue.

2 participants