cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.19k stars 3.82k forks source link

[SHOW CREATE]: Display crdb_internal_idx_expr_1 instead of truthy expr #130542

Open h3n4l opened 2 months ago

h3n4l commented 2 months ago

Describe the problem I use SHOW CREATE ALL TABLES to dump CockroachDB's schema. The output is:

defaultdb=> SHOW CREATE ALL TABLES;
                                         create_statement
---------------------------------------------------------------------------------------------------
 CREATE TABLE public.accounts (                                                                   +
         id UUID NOT NULL DEFAULT gen_random_uuid(),                                              +
         balance INT8 NULL,                                                                       +
         CONSTRAINT accounts_pkey PRIMARY KEY (id ASC)                                            +
 );
 CREATE TABLE public.t (                                                                          +
         id INT8 NULL,                                                                            +
         id2 INT8 NULL,                                                                           +
         CONSTRAINT t_pkey PRIMARY KEY (crdb_internal_idx_expr ASC, crdb_internal_idx_expr_1 DESC)+
 );

Instead of crdb_internal_idx_expr, I need the original expr.

To Reproduce

  1. Create a table using below:

    CREATE TABLE t2(id INT, id2 INT, PRIMARY KEY ((id+1) ASC, (id2+1) DESC);
  2. Using SHOW command to get DDL:

    SHOW CREATE TABLE t2
  3. Get the output containing crdb_internal_idx_expr.

Environment:

Additional context I need to use this DDL to set up other tenant database quickly.

Jira issue: CRDB-42113

Epic CRDB-43310

blathers-crl[bot] commented 2 months ago

Hi @h3n4l, please add branch-* labels to identify which branch(es) this C-bug affects.

:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

blathers-crl[bot] commented 2 months ago

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

Hoot - a bug! Though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here.

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:

:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

h3n4l commented 2 months ago

Also, I found that the SHOW CREATE ALL TABLES only returns the table/view under the public schema. Is this intentional? If yes, if I want to dump the tables/views under all schemas, do I need to set the search path? NVM this comment