1

I can see in my Hosting server which one of my WordPress customers has installed a pluging with name of arrowchat, That plugin is using the query below many many times,

SELECT DISTINCT wp_users.ID userid, wp_users.display_name username, 
                arrowchat_status.session_time lastactivity, 
                wp_users.user_email avatar, wp_users.ID link, 
                arrowchat_status.message, arrowchat_status.status
    FROM wp_users
    JOIN arrowchat_status
        ON wp_users.ID = arrowchat_status.userid
    WHERE ('1391526259' - arrowchat_status.session_time - 60 < '120')
        AND wp_users.ID != 'g2192087'

using explain on MySQL shows that the arrowchat_status is being fetched by MySQL row by row ( all of it's rows ), even making index on arrowchat_status.session_time didn't help, but when I change the WHERE statement to below one, it only fetch 70 rows and runs so much faster.

WHERE (arrowchat_status.session_time >  '1391526319')

As these codes are not mine and I can't make changes to code of my client, is it possible to make some kind of Index in MySQL which help run the old query as fast as new one which I write? Kind of index that can be used in mathematical expressions?

1 Answer 1

0

Such a feature indeed exists and is called expression index or function based index. However, MySQL doesn't support that.

Ref: http://use-the-index-luke.com/sql/where-clause/obfuscation/math

The != condition makes this really tough to index. A index on (userid, session_time) could still help if you'r running on 5.6+ (because of Index Condition Pushdown: http://dev.mysql.com/doc/refman/5.6/en/index-condition-pushdown-optimization.html).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.