tags:

views:

50

answers:

2

All,

I'm wondering if this is a MySQL bug, but since I've seen others playing with larger numbers than this, I'm thinking I'm doing something wrong here.

Here is my table structure for the table I'm querying: mysql> describe ipspace6\G
************* 1. row *************
Field: id
Type: decimal(39,0) unsigned
Null: NO
Key:
Default: NULL
Extra:
************* 2. row *************
Field: addr
Type: decimal(39,0) unsigned
Null: NO
Key: PRI
Default: 0
Extra:
************* 3. row *************
Field: netmask
Type: decimal(39,0) unsigned
Null: NO
Key:
Default: 0
Extra:
************* 4. row *************
Field: subnet
Type: int(4)
Null: NO
Key:
Default: NULL
Extra:

Now, I run a simple SELECT statement against the "id" column:

mysql> SELECT id FROM ipspace6 WHERE id='50552019118453823914642686339427860480';
+----------------------------------------+
| id |
+----------------------------------------+
| 50552019118453823730175245602332344320 |
| 50552019118453823730175245602332344320 |
| 50552019118453823914642686339427860480 |
| 50552019118453823914642686339427860480 |
+----------------------------------------+

...What the heck is going on here? Two of these results are valid, and two definitely are not.

It's not like I'm doing some super-complex nested query or anything, this is simple stuff, and it's driving me insane.

Help, anyone?

+1  A: 

Did you try passing "id" not as a string but as a numeric value?

Cahit
+2  A: 

Remove the quotes. When you operate with any kind of numerics you should always use numbers, not strings.

zerkms
+1, can reproduce problem with quotes, no problem without. Probably casting string to integer instead of decimal for comparison.
Wrikken
Accepted answer, this is exactly what was wrong. I had no idea that MySQL would do that with single-quotes. Thanks!
Andrew K
>> Probably casting string to integer instead of decimal for comparison --- actually mysql is trying to cast the field to the expression it compared to, not vice versa. That's why `id` = '42' (where `id` is an integer) can often be the cause of the performance degradation.
zerkms
Ah, nice to know, will keep it in mind.
Wrikken