Hello,

I have a script that queries a mysql database table. I don't know everything there is to know about making the query as efficient as possible. I know there are primary keys and index columns in my table...HOWEVER my question how much slower it is for php/mysql to search a table using a string rather than a number.

For example. I'm providing content according to the user's request as following:

topic_url_title = 'about-us' and language = 'english'

The topic_url_title is always unique and language may have other alternatives.

How much faster would it be if I had a similar query but with numbers:

topic_id = 27 and language_code = 1

I would appreciate if anyone could offer me a brief explanation.

Thanks in advance!

Thomas

    If topic_url_title and language each has been indexed, then I doubt there would be a significant difference, as the DBMS is then using hte indexes to do most of the work.

      Ok, good to hear. While I was looking at my database table I noticed I hadn't indexed the language column so I went ahead and did it.

      Thanks for your opinion!

        Index ops against ints are usually faster than index ops against text, because text is capable of being much larger and may therefore results in comparing larger amounts of info. for instance, if the average text field you were hitting was 1k letters, it would be much slower than if the average size of the text field was 10 characters.

        OTOH, ints all take up the same space for their type.

        As long as you don't have big text fields a text index will be fine.

        If you have larger fields and / or a lot more of them, switching to an int might help. But that's premature performance tuning. For now don't worry too much, you've got indexes you'll do fine.

          Write a Reply...