My problem is about nature key and auto_increment integer as primary key.
For example, I have tables A
and B
and A_B_relation
. A and B may be some object, and A_B_realtion
record the many to many relation of A and B.
Both A and B have their own global unique id, such as UUID. The UUID is available to user, this means user may query A or B by UUID.
There are two ways to design the table's primary key.
- use the auto_increment integer.
A_B_relation
reference the integer as FK. - use the UUID.
A_B_relation
reference the UUID as FK.
For example, user want to query all the B's info associate with A by A's UUID.
For the first case, the query flow is this:
First, query A's integer primary key by UUID from `A`.
And then, query all the B's integer primary key from `A_B_relation`.
At last, query all the B's info from `B`.
For the latter case, the flow is as below:
Query all the B's UUID from the `A_B_relation` by A's UUID.
Query all the B's info from `B`.
So I think, the latter case is more convenient. Is this right? what's the shortage of the latter case?