Revenue Source

Welcome to the Revenue Source affiliate marketing forums.

You are viewing our internet marketing and SEO forums as a guest which gives you limited access to most of our discussions.  By joining our free community, you will have access to post affiliate marketing topics, communicate privately with other members (PM), exchange SEO strategies, and access many other special features.  Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems, please don't hesitate to contact us.

Go Back   Revenue Source > Site Design & Development > Databases
Reload this Page MySQL automatic data truncation can backfire
Tags: , , , ,

Reply
 
LinkBack Thread Tools Search this Thread
Old
  (#1 (permalink))
Affiliate Blogs is Offline
Revenue Source Veteran
Affiliate Blogs has a brilliant future here!
 
Affiliate Blogs's Avatar
 
Join Date: Oct 2005
Posts: 8,777
Jack of All Trades
CyberSpace United States
   
MySQL automatic data truncation can backfire - 01-09-2007

I had a fun case today.
There is set of cache tables which cache certain content in MyISAM tables and queries for these tables such as:
PLAIN TEXT
SQL:
  1. [FONT='Courier New', Courier, monospace]SELECT DATA FROM cache0003 WHERE `key`=2342526263 AND real_key='cp_140797_6460aad5d2e50d3e859e8649007686ac'; [/font]



The "key" is CRC32 of the real key which is used to keep index size as small as possible so if we have a cache miss we can in most case learn it without going to the disk.
So far so good.
The problem I discovered however is some of these queries would take enormous amount of time while CRC32 conflicts are really rare.
Looking deep into the problem I found out PHP and MySQL are both to blame. PHP is to blame because in 32bit PHP version result of crc32() function was returned as signed integer, in 64bit build of same PHP version it became signed.
The system worked on 32bit platform initially so "key" column was defined as "int"
As it was migrated to 64bit platform we got unsigned 32bit values which did not fit in this column any more so MySQL was silently converting them to 2^32-1, in just about 50% of the cases. This one is kind of expected.
What was unexpected however is how MySQL executed select queries if key value would be out of signed int range.
Instead of simply telling "impossible where noticed" as we have value outside of rage of values which can possibly be in the database we have MySQL truncating this value to 2^32-1, then performing index ref lookup (traversing about half of the rows in pages as cardinality for this constant is low) and discarding all of them before no values matched supplied key value.
So beware, data truncation can backfire in a ways you might not ever expect


MySQL automatic data truncation can backfire - Read More...
  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads for: MySQL automatic data truncation can backfire
Thread Thread Starter Forum Replies Last Post
PHPBuilder.com: Import MS Access Data to MySQL 5 Affiliate Blogs Programming Help 0 11-30-2006 06:29 PM
DevShed: Using Visitor Objects with MySQL Data Sets in PHP 5 Affiliate Blogs Programming Help 0 11-28-2006 05:08 AM
Tutorial: Automatic Sitemap for WordPress SEO Blogs SEO / SEM 0 11-16-2006 03:20 AM
Using Sphinx as MySQL data retrieval accelerator Affiliate Blogs Databases 0 11-14-2006 10:03 PM
Automatic Reciprocal Link Exchange and its big NOs. ToolInventor Search Engine Optimization / Marketing 0 07-03-2006 09:33 AM



© 2004-6 RevenueSource.com.  All rights reserved.  Do not duplicate or redistribute in any form.
This website and its logos/design are property of RevenueSource.com.  All rights reserved. vBSEO 3.2.0 RC7


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34