Home » Performance » MySQL » Surprising: Where a quote usage dramatically slows down a request
Surprising: Where a quote usage dramatically slows down a request [message #1733] Tue, 04 September 2007 08:33 Go to next message
sdeluca  is currently offline sdeluca
Messages: 4
Registered: September 2007
Location: France
Junior Member
Hi there,

I wanted to subtmit a weird finding while optimizing our backend access (MySql 5.0.32-Debian_7etch1-log).

I have a table with the primary indexed column user_id (mediumint ( 8 )).

With the following code, we update some user's infos:

UPDATE phpbb_users SET flastcellupload = '1188382472' , fidcell='10459' WHERE user_id = '10915207';
Query OK, 0 rows affected (3.38 sec)
Rows matched: 0  Changed: 0  Warnings: 0

Note that user_id 10915207 does not exists (and card(user_id)=670+K).

This request takes 3+s to be executed.

And what if I remove the quote around the number, as follows?:
UPDATE phpbb_users SET flastcellupload = '1188382472' , fidcell='10459' WHERE user_id = 10915207;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

As you can see, it takes almost nothing to perform.

I ran some similar tests on SELECT and I can say it has no effect (very quick in both syntaxex).

Any toughts?

Thanks in advance,
Sdl


Come and enjoy http://mobilezoo.biz and http://boursomac.com
Re: Surprising: Where a quote usage dramatically slows down a request [message #1735 is a reply to message #1733 ] Tue, 04 September 2007 15:16 Go to previous messageGo to next message
srynonick  is currently offline srynonick
Messages: 6
Registered: August 2007
Junior Member
i don't know why its faster on select, but user_id is a number, integer, and therefore it shouldnt be user_id='x' but user_id=x, as 'x' means a string.
Re: Surprising: Where a quote usage dramatically slows down a request [message #1738 is a reply to message #1735 ] Tue, 04 September 2007 19:36 Go to previous messageGo to next message
sdeluca  is currently offline sdeluca
Messages: 4
Registered: September 2007
Location: France
Junior Member
thx srynonick for your answer. But I'm afraid a SQL query is by essence a string. So I dono why putting single quote should slow down that way.

And, btw, I forgot to mention that the update does not suffer from slow down if I use an user_id which is smaller (for ex 600000).

Does it have to do with mediumint?


Come and enjoy http://mobilezoo.biz and http://boursomac.com
Re: Surprising: Where a quote usage dramatically slows down a request [message #1741 is a reply to message #1733 ] Wed, 05 September 2007 03:55 Go to previous messageGo to next message
srynonick  is currently offline srynonick
Messages: 6
Registered: August 2007
Junior Member
maybe mysql isn' that intelligent an makes a conversion to int (the value) or the content of the row (to string) on every row.
Re: Surprising: Where a quote usage dramatically slows down a request [message #1750 is a reply to message #1733 ] Wed, 05 September 2007 10:16 Go to previous message
Peter  is currently offline Peter
Messages: 405
Registered: August 2006
Senior Member
Super Guru
Is it 100% repeatable ?
(It could be first update was just uncached)

If yes take a look at Handler_XXX increments while running first and second query

If they are different file a bug with MySQL.

String->Number conversion should work fine as it is deterministic.
It is Number->String which usually slow things down.


Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
Previous Topic:100% Connections Usage Problem
Next Topic:Tables get locked and won't unlock
Goto Forum:
  



Current Time: Thu Jan 8 19:45:13 EST 2009

Total time taken to generate the page: 0.16800 seconds
.:: Contact :: Home :: MySQL Support by Percona.com ::.

Powered by: FUDforum 2.7.5.
Copyright ©2001-2006 FUD Forum Bulletin Board Software

MySQL Performance | Forum authority Badge