Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2004-08-22, 02:59 PM
Junior Member
 
Join Date: Aug 2004
Posts: 2
Jet Black
Default

Ok I've tried everythign I could find in documentation.

Background:

I have a table of 9 index'd columns, some are varchar, some are int. The indexes can be null and duplicated.

I need to search the table on any number of permutations of the keys such as:

select * from table where key1='asdf' or key2='jkl;' or key3='qwer';

as SOON as I introduce an OR in the expression mysql refuses to use a key lookup and resolves to a table scan. I'm intent on processing atleast 150000 keys, so spending 1.xxx secodns to do a search is unacceptable.

I have found a workaround that I dont like

select * from table where key1='asdf' UNION select * from table where key2='jkl;' UNION select * from table where key3='qwer';

Now since each query uses only 1 key, they are each accomplished using indexing and the unioned query works about 30 times faster. I'm not satisfied with this as dooing from 3 to 9 selects then a duplicate removal to accomplish what can be done with one is not good programming, plus my workaround will slow with the number of keys I search at a time..I.E. if I search all 9 keys at a time, it will noticibly slow down.


I have done the following:
tried FORCE INDEX(key1,key2...)
tried ANALYZE TABLE
upgraded to mysql 4.20 since force index wasnt supported by 3.23
tried all sorts of permutations of the keys, as soon as any OR is introduced they are ignored
checked the oputput from explain select .... to see if my keys were beeing used


I can live with my workaround, but I want a better solution, if I cant get it to use the index's this seems like a nice bug

Cheers

Pierre
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2004-08-22, 03:30 PM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

Are your indexes on single fields?
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #3 (permalink)  
Old 2004-08-22, 04:44 PM
Junior Member
 
Join Date: Aug 2004
Posts: 2
Jet Black
Default

Yes each field is beeing single indexed, I.E. I have 9 keys, each is indexed...so all in all I have 9 index's.

I cant use multiple column index's since I need to be able to handle any permutation of keys.

I.E. Key1 and key2 or key1 abd key3 or key1 and key4 or key 3 and key 4 blah blah blah.

Of coulrse I could create more and more restrictive muiltiple column keys such as
key1_key2_key3_key4_key5 then key2_key3_key4_key5 then key3_key4_key5 then key4_key5 then key5

taking advantage of mysql's key prefixing. This would work, as long as I allways query using the same order.

Infact its not a bad idea :lol: dammit.....but I cant use it cause when I only have key1 and key3, I have to search key1_*_key3
which I cant do with a multicolumn key
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

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

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



All times are GMT -5. The time now is 11:32 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.