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

Support for hex & shard in vindex query #7044

Merged
merged 2 commits into from
Nov 24, 2020

Conversation

aquarapid
Copy link
Contributor

@aquarapid aquarapid commented Nov 16, 2020

This uses #6260 as a base, see that for history.

Few things:

  • Renamed hex(keyspace_id) -> hex_keyspace_id, otherwise you cannot select it as it's own column (the sql parser will think you're trying to apply a function)
  • Display the hex_keyspace_id values without 0x prefixes, following the MySQL HEX() convention.
  • One remaining issue (which I'm not sure we can/should solve) is that if you have a single-shard keyspace where you've initialized the shard as 0 instead of -, you will receive - back as your shard "range". You will have to then convert this back to 0 as if you want to go ahead and use it to target a shard.

As an example using our local 101_initial_cluster.sh cluster example:

  • Apply the vschema to the commerce keyspace:
{
"sharded": true,
"vindexes": {
  "hash": {
    "type": "hash"
  },
  "xxhash": {
    "type": "xxhash"
  }
}
}
  • Now you can query the hash and xxhash vindex:
$ mysql  -u root -P 15306 -h 127.0.0.1  -A  -c
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
.
.
.

mysql> use commerce;
Database changed

mysql> select * from hash where id = 1004\G
*************************** 1. row ***************************
           id: 1004
  keyspace_id: �>򥍮ٞ
  range_start: 
    range_end: 
hex_keyspace_id: d03ef2a58daed99e
        shard: -
1 row in set (0.00 sec)

mysql> select * from xxhash where id = 1004\G 
*************************** 1. row ***************************
           id: 1004
  keyspace_id: k�2�[�1v
  range_start: 
    range_end: 
hex_keyspace_id: 6bb432a45b8d3176
        shard: -
1 row in set (0.00 sec)

mysql> select hex_keyspace_id from xxhash where id = 1004\G
*************************** 1. row ***************************
hex_keyspace_id: 6bb432a45b8d3176
1 row in set (0.01 sec)

Signed-off-by: Alex Charis <acharis@hubspot.com>

Signed-off-by: Jacques Grove <aquarapid@gmail.com>
  you cannot extract that column by itself.
Fix tests

Signed-off-by: Jacques Grove <aquarapid@gmail.com>
@harshit-gangal
Copy link
Member

cc: #4501

Copy link
Member

@harshit-gangal harshit-gangal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Any reason for keeping it in draft mode?

@aquarapid
Copy link
Contributor Author

Only reason I left in draft was to see if anyone had an opinion/idea around the '0' vs '-' shard naming thing.

@deepthi
Copy link
Member

deepthi commented Nov 23, 2020

Only reason I left in draft was to see if anyone had an opinion/idea around the '0' vs '-' shard naming thing.

I think that is fine for now. I can't find the reference but @sougou had stated that 0 is still around because that is how things started but - is now the canonical single shard.

@aquarapid aquarapid marked this pull request as ready for review November 23, 2020 22:26
@harshit-gangal harshit-gangal merged commit 39ce3f5 into vitessio:master Nov 24, 2020
@harshit-gangal harshit-gangal deleted the jg_keyspaceid branch November 24, 2020 04:12
@harshit-gangal harshit-gangal added this to the v9.0 milestone Nov 24, 2020
@harshit-gangal harshit-gangal added Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature) labels Nov 24, 2020
@derekperkins
Copy link
Member

This is awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants