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

SHOW INDEX/ES stmts information about computed indexes is misleading #94690

Closed
lopezator opened this issue Jan 4, 2023 · 3 comments · Fixed by #95413
Closed

SHOW INDEX/ES stmts information about computed indexes is misleading #94690

lopezator opened this issue Jan 4, 2023 · 3 comments · Fixed by #95413
Assignees
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@lopezator
Copy link
Contributor

lopezator commented Jan 4, 2023

Is your feature request related to a problem? Please describe.

Imagine the following schema:

CREATE TABLE foo (id string PRIMARY key, json JSON);

With the following index:

CREATE INDEX foo__json__bar ON foo (id, (json->>'bar'));

If I use my IDE to get information about which JSON property I am indexing, I get this:

imagen

Just crdb_internal_idx_expr which is not very useful.

Which is indeed the same information I get if I execute the following stmt:

SHOW INDEXES FROM foo
  table_name |   index_name   | non_unique | seq_in_index |      column_name       | direction | storing | implicit | visible
-------------+----------------+------------+--------------+------------------------+-----------+---------+----------+----------
  foo        | foo__json__bar |     t      |            1 | id                     | ASC       |    f    |    f     |    t
  foo        | foo__json__bar |     t      |            2 | crdb_internal_idx_expr | ASC       |    f    |    f     |    t
  foo        | foo_pkey       |     f      |            1 | id                     | ASC       |    f    |    f     |    t
  foo        | foo_pkey       |     f      |            2 | json                   | N/A       |    t    |    f     |    t
(4 rows)

To get useful information about the index, I have to use:

SHOW CREATE TABLE foo
  table_name |                        create_statement
-------------+-----------------------------------------------------------------
  foo        | CREATE TABLE public.foo (
             |     id STRING NOT NULL,
             |     json JSONB NULL,
             |     CONSTRAINT foo_pkey PRIMARY KEY (id ASC),
             |     INDEX foo__json__bar (id ASC, (json->>'bar':::STRING) ASC)
             | )
(1 row)

Where I can see the useful piece of information I was looking for, but it seems a bit misleading having to use SHOW CREATE TABLE to gather information about an index. IMHO SHOW INDEXES returning it would be awesome, and possibly the IDEs could benefit from this feature as well.

Describe the solution you'd like

Return the json/computed column information in the SHOW INDEXES stmt:

INDEX foo__json__bar (id ASC, (json->>'bar':::STRING) ASC)

Describe alternatives you've considered

I can use SHOW CREATE TABLE foo for now, but it's not very intuitive.

Additional context

Thank you Shaun (Cockroach Labs) from CockroachDB Community Slack for the useful tip!

Jira issue: CRDB-23086

Epic CRDB-23454

@lopezator lopezator added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Jan 4, 2023
@blathers-crl
Copy link

blathers-crl bot commented Jan 4, 2023

Hello, I am Blathers. I am here to help you get the issue triaged.

I was unable to automatically find someone to ping.

If we have not gotten back to your issue within a few business days, you can try the following:

  • Join our community slack channel and ask on #cockroachdb.
  • Try find someone from here if you know they worked closely on the area and CC them.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-untriaged blathers was unable to find an owner labels Jan 4, 2023
@yuzefovich yuzefovich removed the X-blathers-untriaged blathers was unable to find an owner label Jan 4, 2023
@blathers-crl blathers-crl bot added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label Jan 4, 2023
@rafiss
Copy link
Collaborator

rafiss commented Jan 10, 2023

Thanks for the request! Out of curiosity, do you know what information the IDE would display if you created the same kind of index in PostgreSQL? There may be a pg_catalog table that we should populate.

@lopezator
Copy link
Contributor Author

lopezator commented Jan 11, 2023

Thanks for the request! Out of curiosity, do you know what information the IDE would display if you created the same kind of index in PostgreSQL? There may be a pg_catalog table that we should populate.

Hello! In postgres the feedback is more descriptive 🙂

imagen

Let me know if you need something else.

Thank you for the quick reply @rafiss !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants