Home » Performance » MySQL » Self-made index: faster or slower?
Self-made index: faster or slower? [message #478] Tue, 19 December 2006 09:27 Go to next message
willybnl2  is currently offline willybnl2
Messages: 6
Registered: December 2006
Junior Member
Probably a very simple question to answer for real experts, but i'm doubting I will answer it myself without having to experience this in real life (maybe when it is to late). This will be used for on website that is queryed very very frequently.

The problem:
Having natural language lines in a database (in multiple language columns).
(example: 'This is a sentence')
Want to be able to search for this in the fastest way possible.
(example: search for all rows containing 'this' and 'sentence'.)

1st conclusing:
-normal index would not work as you have to search with %..% in this as it are lines not words.
-Normal fulltext index is not sufficient as pairs have to be made for every column combination possible. And as i have some 32 languages... Smile

My solution:
Create a new table that excists of this:

unique column 1 column 2
word id1,id2,idX id9,id8,idX

and i query this (could even do this using soundex to help visitor after this step) and then do Select * from [table] where id in (id1,id2,idX).

On first sight you might think it would be faster (if i combine this into 1 query), but already some premature testing on my machine shows that something like

select * from [table] where column1 like '% someword %' OR column1 like '% someotherword %' OR column2 like '% someword %' OR column1 like '% someotherword %'

is faster than only the Select * from [table] where id in (id1,id2,idX)

Not even talking about first selecting better results.

My question:
- Should this in the end prove faster? Or can i better stick with the %..% that does not use the index.
(is there maybe a better way to do this)
Re: Self-made index: faster or slower? [message #479 is a reply to message #478 ] Tue, 19 December 2006 10:35 Go to previous message
Peter  is currently offline Peter
Messages: 405
Registered: August 2006
Senior Member
Super Guru
Depending on the size of the database your solution might perform reasonable or be way to slow.

I would recommend using sphinx (http://www.sphinxsearch.com) for this kind of task - with it you can specify which columns you want to search


Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
Previous Topic:Choosing InnoDB or NDB Engine?
Next Topic:Degree of Separation Calculation
Goto Forum:
  



Current Time: Wed Jan 7 18:40:39 EST 2009

Total time taken to generate the page: 0.02216 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