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

Dolt doesn't respect primary key for sort order #2070

Closed
zachmu opened this issue Aug 30, 2021 · 3 comments
Closed

Dolt doesn't respect primary key for sort order #2070

zachmu opened this issue Aug 30, 2021 · 3 comments
Assignees

Comments

@zachmu
Copy link
Member

zachmu commented Aug 30, 2021

If you declare a table like so:

create table test (a int, b int, c int, primary key (b,a))

Dolt's uses (a,b) as the key for internal sorting. This typically isn't visible to clients so it isn't a major bug, but should still be fixed.

This behavior is due to go-mysql-server's schema interface treating primary key as a boolean attribute of a column, when it should be a distinct top-level entity.

@bheni
Copy link
Contributor

bheni commented Aug 30, 2021

~/test>dolt init
Successfully initialized dolt data repository.

~/test>dolt sql -q 'CREATE TABLE test (pk BIGINT, c1 BIGINT, PRIMARY KEY(c1,pk));'

~/test>dolt sql -q 'INSERT INTO test VALUES (0,5),(1,4),(2,3),(3,2),(4,1),(5,0);'
Query OK, 6 rows affected

~/test>dolt table export test temp.csv -f
Successfully exported data.

~/test>cat temp.csv
pk,c1
0,5
1,4
2,3
3,2
4,1
5,0

@zachmu
Copy link
Member Author

zachmu commented Nov 20, 2021

This is a major bug now that indexed lookups are better. Max to address.

@timsehn
Copy link
Sponsor Contributor

timsehn commented Aug 30, 2022

This is fixed:

test-pk-order $ dolt init --new-format
Successfully initialized dolt data repository.
test-pk-order $ dolt sql -q 'CREATE TABLE test (pk BIGINT, c1 BIGINT, PRIMARY KEY(c1,pk));'
test-pk-order $ dolt sql -q 'INSERT INTO test VALUES (0,5),(1,4),(2,3),(3,2),(4,1),(5,0);'
Query OK, 6 rows affected
test-pk-order $ dolt sql -q "select * from test";
+----+----+
| pk | c1 |
+----+----+
| 5  | 0  |
| 4  | 1  |
| 3  | 2  |
| 2  | 3  |
| 1  | 4  |
| 0  | 5  |
+----+----+

@timsehn timsehn closed this as completed Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants