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 8094811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:55:08+00:00 2026-06-05T20:55:08+00:00

I am trying to optimize this query as good as possible,but still i am

  • 0

I am trying to optimize this query as good as possible,but still i am getting query locks due to this query.Can any one provide some suggestions in improving it.The query fetches the last one day entries from the table.

The QUERY:

SELECT CR.id,
       CR.servicecode,
       CR.leadtime,
       CR.redirecturl,
       CRE.custemail,
       CRE.custlname,
       CRE.custfname,
       CRE.duration,
       CR.userid,
       AA.lpintrotimearr,
       AA.lpintrotimedep,
       AA.landdatetimearr,
       AA.landdatetimedep,
       CR.newcustid,
       cre.CRE.custmobilephone,
       CRE.brandname
FROM   response CR
       LEFT JOIN agreement AA
              ON CR.id = AA.id
       LEFT JOIN request CRE
              ON CRE.id = CR.id
WHERE  CR.id > '20120617145243'
       AND CR.approved = 1
       AND CR.chlapproved != 0
       AND CR.chlapproved IS NOT NULL
       AND AA.id IS NOT NULL
       AND ( AA.stdsign != 'on'
              OR AA.stdsign IS NULL )
       AND ( AA.ivaflag = 0
              OR AA.ivaflag IS NULL )
       AND ( AA.opt IS NULL
              OR AA.opt = 0 );

The EXPLAIN:

Explain commands result

One way is to index all 3(AA.stdsign,AA.ivaflag and AA.opts) columns but all the three flags (AA.stdsign,AA.ivaflag and AA.opts) can have only 3 different values.Will indexing these reduce query run time?

All the ids are of varchar(60) data type.

  • 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-06-05T20:55:09+00:00Added an answer on June 5, 2026 at 8:55 pm

    There isn’t much to be improved on the query itself.
    On the other hand, setting an index on AA.stdsign, AA.ivaflag and AA.opts should help a lot.

    As your EXPLAIN indicates, no suitable key is found for your AA table and all 534956 rows must be scanned to satisfy the WHERE clause.

    [edit]
    One last tip: using large column types (such as VARCHAR(60)) for your primary keys is probably sub-optimal.

    First reason: every time you need to reference a row (e.g. in a foreign key), you need another VARCHAR(60).

    Second reason: comparisons on strings are slower than on integers (hence it may render a JOIN slower than necessary)

    You may want to add an INT column to your tables, and use it as primary key.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to optimize this query. It is not slow for now but
Can anyone one help me optimize this query SELECT `debit_side`.`account_code` CODE, GROUP_CONCAT(DISTINCT accounts.name) AS
I'm trying to optimize this mysql query using EXPLAIN. Can somebody please help me
I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because
I am trying to optimize a query that does something like this: SELECT ...
Hey guys, trying to optimize this query to solve a duplicate user issue: SELECT
We are trying to optimize some of our queries. One query is doing the
i'm trying to get optimize an very old query that i can't wrap my
I'm trying to optimize this query because the DB it runs against is huge
I am trying to run this query on http://dbpedia.org/sparql but I get an error

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.