Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6594111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:46:07+00:00 2026-05-25T17:46:07+00:00

I am using a time profiler for optimizing my python script. It turns out

  • 0

I am using a time profiler for optimizing my python script. It turns out that mysql queries are taking lot of time in my python scripts. There are total of only 19 queries. These 19 mysql queries take over 7.44 secs as reported by cProfile.

Following is the complete script footprint, with mysql query and respective query time in secs.

$ python -m cProfile -s time myscript.py 
MYSQL Queries
SELECT column FROM table WHERE foreign_key = 1 AND somecolumn='val1'
0.378623008728
SELECT column FROM table WHERE foreign_key = 1 AND somecolumn='val2'
0.379124879837
...
SELECT column FROM table WHERE foreign_key = 1 AND somecolumn='val19'
0.377450942993

   60122 function calls (59599 primitive calls) in 7.634 CPU seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
       20    7.440    0.372    7.440    0.372 {method 'query' of '_mysql.connection' objects}
       22    0.025    0.001    0.025    0.001 {method 'execute' of 'psycopg2._psycopg.cursor' objects}
        2    0.008    0.004    0.008    0.004 {method 'commit' of 'psycopg2._psycopg.connection' objects}
     1299    0.007    0.000    0.011    0.000 posixpath.py:59(join)
      982    0.007    0.000    0.007    0.000 {posix.lstat}
      429    0.006    0.000    0.010    0.000 text_file.py:162(readline)
        1    0.006    0.006    0.006    0.006 {psycopg2._psycopg.connect}
        1    0.006    0.006    0.025    0.025 __init__.py:18(<module>)
        2    0.004    0.002    0.007    0.004 connections.py:62(__init__)
      110    0.004    0.000    0.027    0.000 posixpath.py:344(realpath)
       20    0.004    0.000    0.004    0.000 {method 'store_result' of '_mysql.connection' objects}

...

Can anyone help me figure out the reason?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:46:07+00:00Added an answer on May 25, 2026 at 5:46 pm

    Probably you forgot to create an index on (foreign_key, somecolumn) resulting in MySQL needing to perform a full table scan to find the data. You can see this by running with EXPLAIN:

    EXPLAIN SELECT column FROM table WHERE foreign_key = 1 AND somecolumn='val1'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can examine the optimization using profiler, size of the executable file and time
Something I wrote throws a lot of AttributeError exceptions when using time.strptime() inside a
Using the new MySQL Query Profiler in PHPMyAdmin version 2.11.5, I got following results
Is there free and good line-level profiler for PHP? I'm using xdebug and it's
Hey, I'm totally behind this topic. Yesterday I was doing profiling using Python profiler
When dealing with debugging queries using Profiler and SSMS, its pretty common for me
I have a report that renders data returned from a stored procedure. Using profiler
I ran the profiler in firebug and found that the most time costly function
It's my first time using SQL Server Profiler and I'm wondering how can i
Is there an explanation of these statuses anywhere? http://dev.mysql.com/tech-resources/articles/using-new-query-profiler.html my specific question is in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.