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

[YSQL] Range columns of a primary key out-of-order #1250

Closed
robertpang opened this issue Apr 24, 2019 · 0 comments

Comments

@robertpang
Copy link
Contributor

commented Apr 24, 2019

When a user creates a YSQL table with a compound primary key, the range columns after the first implicit hash column are incorrectly created in the same order as they are in the columns' cardinal order, not in the order listed in the primary key. For example,

postgres=# create table t (r2 int, r1 int, h int, primary key (h, r1, r2));
CREATE TABLE
postgres=# \d t
                 Table "public.t"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 r2     | integer |           | not null |
 r1     | integer |           | not null |
 h      | integer |           | not null |
Indexes:
    "t_pkey" PRIMARY KEY, btree (h, r1, r2)

The column order as appeared in yb-master is:

Column | ID | Type
------ | -- | ----------------------------
h      |  0 | int32 NOT NULL PARTITION KEY
r2     |  1 | int32 NOT NULL NOT A PARTITION KEY
r1     |  2 | int32 NOT NULL NOT A PARTITION KEY

@robertpang robertpang added this to To do in SQL Support via automation Apr 24, 2019

@ndeodhar ndeodhar moved this from To do to In progress in SQL Support Jul 10, 2019

@ndeodhar ndeodhar added this to the v2.0 milestone Aug 28, 2019

@ndeodhar ndeodhar assigned ndeodhar and d-uspenskiy and unassigned OlegLoginov Aug 28, 2019

d-uspenskiy added a commit that referenced this issue Sep 4, 2019
#1250 [YSQL] Order range columns with respect to primary key descript…
…ion [format change]

Summary:
Table columns are added in the following order:
- hash component of compound primary key (first column in compound primary key description)
- range components of compound primary key (same order as described in compound primary key)
- non key columns (same order as described in `CREATE TABLE` statement)

Test Plan:
New unit test was introduced

```
yb_build.sh --cxx-test pg_libpq-test --gtest_filter PgLibPqTest.CompoundKeyColumnOrder
```

Reviewers: neil, mihnea, neha

Reviewed By: neha

Subscribers: kannan, neha, yql

Differential Revision: https://phabricator.dev.yugabyte.com/D7134

@d-uspenskiy d-uspenskiy closed this Sep 4, 2019

SQL Support automation moved this from In progress to Done Sep 4, 2019

d-uspenskiy added a commit to d-uspenskiy/yugabyte-db that referenced this issue Sep 5, 2019
YugaByte#1250 [YSQL] Order range columns with respect to primary key …
…description [format change]

Summary:
Table columns are added in the following order:
- hash component of compound primary key (first column in compound primary key description)
- range components of compound primary key (same order as described in compound primary key)
- non key columns (same order as described in `CREATE TABLE` statement)

Test Plan:
New unit test was introduced

```
yb_build.sh --cxx-test pg_libpq-test --gtest_filter PgLibPqTest.CompoundKeyColumnOrder
```

Reviewers: neil, mihnea, neha

Reviewed By: neha

Subscribers: kannan, neha, yql

Differential Revision: https://phabricator.dev.yugabyte.com/D7134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.