[UPHPU] A Good GUID/UUID PHP Solution

Gary Thornock gthornock at yahoo.com
Tue Jul 21 12:20:58 MDT 2009


--- On Tue, 7/21/09, Kirk Ouimet <kirk at kirkouimet.com> wrote:
> Can anyone recommend a good PHP function/class to generate
> GUIDs? I'm shifting from using auto-increment to using GUIDs -
> any advice for this type of change? Does a SQL lookup slow down
> using a GUID as a PK versus using an integer as a PK?

Database engines that use clustered indexes (data rows whose
primary keys are close in value are physically stored close
together on disk) will see a slowdown if you use any randomly
distributed value (including a GUID) as the primary key.  Inserts
are particularly bad, but reads can be problematic as well
because there's no locality to help in caching "nearby" values.

GUIDs can be useful as your application's key (which you would
set as an additional unique index on the table), but for the
database engine, you're usually better off using a consistently
increasing value like an auto-increment as the primary key.

Note, of course, that "usually" != "always", you may find some
particular edge case where the rule of thumb doesn't apply.



More information about the UPHPU mailing list