Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6295 > unrolled thread
| Started by | "kurtk@pobox.com" <kurtk@pobox.com> |
|---|---|
| First post | 2012-06-11 17:16 -0700 |
| Last post | 2012-06-19 03:32 -0700 |
| Articles | 9 — 5 participants |
Back to article view | Back to comp.lang.php
Is spl_object_hash unique in the SQL sense? Can it be used as a unique SQL db column? "kurtk@pobox.com" <kurtk@pobox.com> - 2012-06-11 17:16 -0700
Re: Is spl_object_hash unique in the SQL sense? Can it be used as a unique SQL db column? Jerry Stuckle <jstucklex@attglobal.net> - 2012-06-11 20:24 -0400
Re: Is spl_object_hash unique in the SQL sense? Can it be used as a unique SQL db column? "kurtk@pobox.com" <kurtk@pobox.com> - 2012-06-12 11:47 -0700
Re: Is spl_object_hash unique in the SQL sense? Can it be used as a unique SQL db column? Jerry Stuckle <jstucklex@attglobal.net> - 2012-06-12 15:06 -0400
Re: Is spl_object_hash unique in the SQL sense? Can it be used as a unique SQL db column? "Peter H. Coffin" <hellsop@ninehells.com> - 2012-06-12 14:26 -0500
Re: Is spl_object_hash unique in the SQL sense? Can it be used as a unique SQL db column? Jerry Stuckle <jstucklex@attglobal.net> - 2012-06-12 19:34 -0400
Re: Is spl_object_hash unique in the SQL sense? Can it be used as a unique SQL db column? Captain Paralytic <paul_lautman@yahoo.com> - 2012-06-13 04:09 -0700
Re: Is spl_object_hash unique in the SQL sense? Can it be used as a unique SQL db column? Goran <goran@nospam.com> - 2012-06-13 13:40 +0200
Re: Is spl_object_hash unique in the SQL sense? Can it be used as a unique SQL db column? Captain Paralytic <paul_lautman@yahoo.com> - 2012-06-19 03:32 -0700
| From | "kurtk@pobox.com" <kurtk@pobox.com> |
|---|---|
| Date | 2012-06-11 17:16 -0700 |
| Subject | Is spl_object_hash unique in the SQL sense? Can it be used as a unique SQL db column? |
| Message-ID | <b3a88b31-765b-4537-adfd-563c4734c66a@googlegroups.com> |
Does anyone know definitely whether the results of spl_object_hash be safely used as a unique database column?
[toc] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-06-11 20:24 -0400 |
| Message-ID | <jr627b$aqj$1@dont-email.me> |
| In reply to | #6295 |
On 6/11/2012 8:16 PM, kurtk@pobox.com wrote: > Does anyone know definitely whether the results of spl_object_hash be safely used as a unique database column? No, hashes can never guaranteed to be unique. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | "kurtk@pobox.com" <kurtk@pobox.com> |
|---|---|
| Date | 2012-06-12 11:47 -0700 |
| Message-ID | <a3acc71e-a388-47ed-97c5-72f4d04c40e5@googlegroups.com> |
| In reply to | #6296 |
> No, hashes can never guaranteed to be unique. I opted to use md5(uniqid()); to create a unique key.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-06-12 15:06 -0400 |
| Message-ID | <jr840g$que$2@dont-email.me> |
| In reply to | #6308 |
On 6/12/2012 2:47 PM, kurtk@pobox.com wrote: >> No, hashes can never guaranteed to be unique. > > I opted to use > > md5(uniqid()); > > to create a unique key. > Still not guaranteed to be unique. Hashes never are. But if you've only got a few thousand items, the chances of a collision are slim. This is why databases have sequence or auto-increment values. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | "Peter H. Coffin" <hellsop@ninehells.com> |
|---|---|
| Date | 2012-06-12 14:26 -0500 |
| Message-ID | <slrnjtf5vi.h39.hellsop@nibelheim.ninehells.com> |
| In reply to | #6308 |
On Tue, 12 Jun 2012 11:47:04 -0700 (PDT), kurtk@pobox.com wrote:
>> No, hashes can never guaranteed to be unique.
>
> I opted to use
>
> md5(uniqid());
>
> to create a unique key.
Still not guaranteed to be unique. You've even got a defined 13-hexdigit
space thing what you're hashing. Which means as soon as you've got more
than 4,503,599,627,370,495 entries, you are GUARANTEED a collision. That
seems like a lot, but you're down to a one in a billion shot at a
collision when you've got a few million entries. And everybody knows,
that one in a billion changes turn up nine times in ten.
--
48. I will treat any beast which I control through magic or technology
with respect and kindness. Thus if the control is ever broken, it
will not immediately come after me for revenge.
--Peter Anspach's list of things to do as an Evil Overlord
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-06-12 19:34 -0400 |
| Message-ID | <jr8jmh$3cp$2@dont-email.me> |
| In reply to | #6311 |
On 6/12/2012 3:26 PM, Peter H. Coffin wrote: > On Tue, 12 Jun 2012 11:47:04 -0700 (PDT), kurtk@pobox.com wrote: >>> No, hashes can never guaranteed to be unique. >> >> I opted to use >> >> md5(uniqid()); >> >> to create a unique key. > > Still not guaranteed to be unique. You've even got a defined 13-hexdigit > space thing what you're hashing. Which means as soon as you've got more > than 4,503,599,627,370,495 entries, you are GUARANTEED a collision. That > seems like a lot, but you're down to a one in a billion shot at a > collision when you've got a few million entries. And everybody knows, > that one in a billion changes turn up nine times in ten. > Peter, I haven't figured out the exact numbers, but I suspect it's much less than one in a billion to have a 50-50 chance. After all - it only takes 24 people to have a 50-50 chance two of them have the same birthday. Odds go down quite a bit more quickly than you think! -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Captain Paralytic <paul_lautman@yahoo.com> |
|---|---|
| Date | 2012-06-13 04:09 -0700 |
| Message-ID | <bafa9abd-6775-4874-b575-a5c00afcd3d3@v9g2000vbc.googlegroups.com> |
| In reply to | #6308 |
On Jun 12, 7:47 pm, "ku...@pobox.com" <ku...@pobox.com> wrote: > > No, hashes can never guaranteed to be unique. > > I opted to use > > md5(uniqid()); > > to create a unique key. Why bother hashing it, why not just use the uniqid() value directly?
[toc] | [prev] | [next] | [standalone]
| From | Goran <goran@nospam.com> |
|---|---|
| Date | 2012-06-13 13:40 +0200 |
| Subject | Re: Is spl_object_hash unique in the SQL sense? Can it be used as a unique SQL db column? |
| Message-ID | <jr9u7s$ln4$1@news.metronet.hr> |
| In reply to | #6319 |
On 13.6.2012 13:09, Captain Paralytic wrote: > On Jun 12, 7:47 pm, "ku...@pobox.com" <ku...@pobox.com> wrote: >>> No, hashes can never guaranteed to be unique. >> >> I opted to use >> >> md5(uniqid()); >> >> to create a unique key. > > Why bother hashing it, why not just use the uniqid() value directly? uniqid() is not truly unique either:D Only truly unique value is the one generated by DB (if we are talking about DB data).
[toc] | [prev] | [next] | [standalone]
| From | Captain Paralytic <paul_lautman@yahoo.com> |
|---|---|
| Date | 2012-06-19 03:32 -0700 |
| Message-ID | <7e2e84b8-9c28-474e-b7c8-646e996bda85@n33g2000vbi.googlegroups.com> |
| In reply to | #6320 |
On Jun 13, 12:40 pm, Goran <go...@nospam.com> wrote: > On 13.6.2012 13:09, Captain Paralytic wrote: > > > On Jun 12, 7:47 pm, "ku...@pobox.com" <ku...@pobox.com> wrote: > >>> No, hashes can never guaranteed to be unique. > > >> I opted to use > > >> md5(uniqid()); > > >> to create a unique key. > > > Why bother hashing it, why not just use the uniqid() value directly? > > uniqid() is not truly unique either:D Only truly unique value is the one > generated by DB (if we are talking about DB data). Err I know that! but hashing it actually REDUCES it's uniqueness.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web