Extremely slow raw SQL queries on web2py

db.executesql () takes 30 seconds to return the result, even though the same query takes 0.5-1 seconds if I try it in the MySQL console or with the same code in the web2py debug console or web2py shell.

dbs._timings #From the first test below
  [('SELECT 1;', 0.016000032424926758), #web2py or driver stuff, I didn't execute it.
   ('SET FOREIGN_KEY_CHECKS=1;', 0.003999948501586914), #web2py or driver stuff, I didn't execute it.
   ("SET sql_mode='NO_BACKSLASH_ESCAPES';", 0.00800013542175293), #web2py or driver stuff, I didn't execute it.
   ("SELECT TIMESTAMPDIFF(...) AS 'duration',\n
            TIMESTAMPDIFF(...)\n
                    - INTERVAL 1 HOUR, TIMESTAMP(...)\n
                    + INTERVAL CAST(...) AS 'timediff',\n
             ris.ODATE as 'date',\n
             CONCAT(...) as 'service'\n
        FROM ... AS ris\n
        JOIN ... as sd on ris.... = sd....\n
        WHERE ris.... != '0000-00-00 00:00:00'\n
              and ris.... != '0000-00-00 00:00:00'\n
              and ris.... >= '2010-8-15'\n
              and ris.... <= '2014-8-22'", 32.0460000038147), # Slow query/code, executed on page view.
     ("SELECT TIMESTAMPDIFF(...) AS 'duration',\n
             TIMESTAMPDIFF(...)\n
                    - INTERVAL 1 HOUR, TIMESTAMP(...)\n
                    + INTERVAL CAST(...) AS 'timediff',\n
             ris.ODATE as 'date',\n
             CONCAT(...) as 'service'\n
        FROM ... AS ris\n
        JOIN ... as sd on ris.... = sd....\n
        WHERE ris.... != '0000-00-00 00:00:00'\n
              and ris.... != '0000-00-00 00:00:00'\n
              and ris.... >= '2010-8-15'\n
              and ris.... <= '2014-8-22'", 0.6069998741149902) #Same query/code, exec. on the debug console]

      

I've tried the following cases:

... #Irrelevant part of the code
raw_data = dbs.executesql(query, as_dict=True) #Takes 30 seconds to return a result
from gluon.debug import dbg
dbg.set_trace() #After this line, I'm on the debug console
raw_data = dbs.executesql(query, as_dict=True) #Takes <1 second to return a result
dbs._timings #print

      

and

... #Irrelevant part of the code
from gluon.debug import dbg
dbg.set_trace() #After this line, I'm on the debug console
raw_data = dbs.executesql(query, as_dict=True) #Takes <1 second to return a result

      

I wonder when I try to execute more queries sequentially:

... #Irrelevant part of the code
raw_data = dbs.executesql(query, as_dict=True) #Takes 7 seconds to return a result
raw_data = dbs.executesql(query, as_dict=True) #Takes 7 seconds to return a result
raw_data = dbs.executesql(query, as_dict=True) #Takes 7 seconds to return a result
from gluon.debug import dbg
dbg.set_trace() #After this line, I'm on the debug console
raw_data = dbs.executesql(query, as_dict=True) #Takes <1 second to return a result

      

on HeidiSQL

/* Affected rows: 0  Found rows: 7,391  Warnings: 0  Duration for 1 query: 0.000 sec. (+ 0.078 sec. network) */

      

+3
performance python web2py mysql


source to share


No one has answered this question yet

Check out similar questions:

3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
2776
How can I prevent SQL injection in PHP?
1762
How to import SQL file using command line in MySQL?
1406
Why does changing 0.1f to 0 slow down performance by 10x?
1066
How do I display the results of MySQL queries in CSV format?
1030
SQL selects only rows with maximum value in column
721
Joining a subquery
678
Why is my program slower if you iterate over exactly 8192 items?
416
How slow are Java exceptions?
229
SQL Server: fast query but slow from procedure



All Articles
Loading...
X
Show
Funny
Dev
Pics