Is it efficient to "pack" two INT
primary keys (a composite key) into a single BIGINT
primary key? Can it be done automatically within mySQL or does it need to be done in the client (PHP, C++)?
I'm creating a directional graph connecting user IDs to one another (e.g. for a friend-finder) in mySQL.
MySQL supports 8-byte BIGINT
s and 4-byte INT
s, so the packer might look something like:
id_edge = ((BIGINT)id_from)*pow(2,31) + ((BIGINT)id_to)
How do the big boys (FB, LI) do it? Is it easier or better to have three "independent" fields:
CREATE TABLE `things`.`connections` (
`id_edge` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'Need a single pk for gii
' ,
`id_from` INT NOT NULL ,
`id_to` INT NOT NULL ,
....