This topic is locked
[SOLVED]

 Slow Queries On Large Databases

5/6/2013 2:37:42 PM
PHPRunner General questions
A
aramuni author

The post below speaks about slow querys using LIKE.
http://www.asprunner.com/forums/topic/13451-slow-queries-on-large-databases/pageviewfindpostp46535
And all the searches comes with "contains" constraints, and that´s does not works with my largests tables, with 40.000.000 or more records.
And we have another problem. If we change to "equal" instead "contains" the query comes with UPPER, and that makes the search extremely slow.
So we have this slow query using "contains":
SELECT COUNT()

FROM Comunicacao

INNER JOIN Celular ON Comunicacao.IMEI = Celular.IMEI

INNER JOIN Usuario ON Celular.Usuario_Usu_id = Usuario.Usu_id

WHERE (1=1) AND (UPPER(Comunicacao.IMEI) LIKE UPPER('%343580%'))
And this slow query using "equal":
SELECT COUNT(
)

FROM Comunicacao

INNER JOIN Celular ON Comunicacao.IMEI = Celular.IMEI

INNER JOIN Usuario ON Celular.Usuario_Usu_id = Usuario.Usu_id

WHERE (1=1) AND (UPPER(Comunicacao.IMEI)=UPPER('423671'))
Using "LIKE" I can´t see how make it fast, but if we can generate the querys without "UPPER" the querys gets 10 times faster, like this:
SELECT COUNT(*)

FROM Comunicacao

INNER JOIN Celular ON Comunicacao.IMEI = Celular.IMEI

INNER JOIN Usuario ON Celular.Usuario_Usu_id = Usuario.Usu_id

WHERE (1=1) AND (Comunicacao.IMEI='423671')
So the question is: How we can generate the querys WITHOUT the UPPER clause?

C
cgphp 5/6/2013

Check this page from the PHPrunner manual: http://xlinesoft.com/phprunner/docs/replacewhere.htm

Sergey Kornilov admin 5/6/2013

There is also an option in PHPRunner to perform case-sensitive search (without UPPER being added).
Check 'Search settings' section at http://xlinesoft.com/phprunner/docs/choose_fields.htm

A
aramuni author 5/6/2013



Check this page from the PHPrunner manual: http://xlinesoft.com/phprunner/docs/replacewhere.htm


Thanks for this nice idea Cristian, but doing this I would not disrupt the search functioning?
The number 423671 for instance comes from a user input on the search panel.
Can we alter the where clause and maintain the search functions working?

C
cgphp 5/6/2013

That number shoud be in the ctlSearchFor GET param. Check the value of $_GET['ctlSearchFor']

A
aramuni author 5/7/2013



There is also an option in PHPRunner to perform case-sensitive search (without UPPER being added).
Check 'Search settings' section at http://xlinesoft.com/phprunner/docs/choose_fields.htm


Thank you Sergey, this was very helpfull, because eliminates the UPPER that appears on the sql query when we use CONTAINS option on an search.