how to decrease executing select query time












-2















decreasing running time (select query executing time)

even query is not working

it is reducing code line

there are 80 tables



select 
(ant_return_loss_pass='pass')+(ant_cross_isolation_pass='pass') as pass_count,
(ant_return_loss_pass='fail')+(ant_cross_isolation_pass='fail') as fail_count,
(ant_return_loss_pass='') +(ant_cross_isolation_pass='') as blank_count
from
(
select A.serial_no,
A.pass_fail as ant_return_loss_pass
from ant_return_loss A,
(
select max(register_date) as date
from ant_return_loss
where 1=1
and serial_no >= '184500074'
and serial_no <= '184500076'
group by serial_no
) B
where 1 = 1
and A.register_date = B.date
)AA
,(
select A.serial_no,
A.pass_fail as ant_cross_isolation_pass
from ant_cross_isolation A,
(
select max(register_date) as date
from ant_cross_isolation
where 1=1
and serial_no >= '184500074'
and serial_no <= '184500076'
group by serial_no
) B
where 1 = 1
and A.register_date = B.date
)BB
where 1=1
and AA.serial_no = BB.serial_no


not working or working 600 sec










share|improve this question

























  • What version of MySQL? Can you provide sample data? and expected results (based on the sample data)?

    – Used_By_Already
    Jan 3 at 4:16
















-2















decreasing running time (select query executing time)

even query is not working

it is reducing code line

there are 80 tables



select 
(ant_return_loss_pass='pass')+(ant_cross_isolation_pass='pass') as pass_count,
(ant_return_loss_pass='fail')+(ant_cross_isolation_pass='fail') as fail_count,
(ant_return_loss_pass='') +(ant_cross_isolation_pass='') as blank_count
from
(
select A.serial_no,
A.pass_fail as ant_return_loss_pass
from ant_return_loss A,
(
select max(register_date) as date
from ant_return_loss
where 1=1
and serial_no >= '184500074'
and serial_no <= '184500076'
group by serial_no
) B
where 1 = 1
and A.register_date = B.date
)AA
,(
select A.serial_no,
A.pass_fail as ant_cross_isolation_pass
from ant_cross_isolation A,
(
select max(register_date) as date
from ant_cross_isolation
where 1=1
and serial_no >= '184500074'
and serial_no <= '184500076'
group by serial_no
) B
where 1 = 1
and A.register_date = B.date
)BB
where 1=1
and AA.serial_no = BB.serial_no


not working or working 600 sec










share|improve this question

























  • What version of MySQL? Can you provide sample data? and expected results (based on the sample data)?

    – Used_By_Already
    Jan 3 at 4:16














-2












-2








-2








decreasing running time (select query executing time)

even query is not working

it is reducing code line

there are 80 tables



select 
(ant_return_loss_pass='pass')+(ant_cross_isolation_pass='pass') as pass_count,
(ant_return_loss_pass='fail')+(ant_cross_isolation_pass='fail') as fail_count,
(ant_return_loss_pass='') +(ant_cross_isolation_pass='') as blank_count
from
(
select A.serial_no,
A.pass_fail as ant_return_loss_pass
from ant_return_loss A,
(
select max(register_date) as date
from ant_return_loss
where 1=1
and serial_no >= '184500074'
and serial_no <= '184500076'
group by serial_no
) B
where 1 = 1
and A.register_date = B.date
)AA
,(
select A.serial_no,
A.pass_fail as ant_cross_isolation_pass
from ant_cross_isolation A,
(
select max(register_date) as date
from ant_cross_isolation
where 1=1
and serial_no >= '184500074'
and serial_no <= '184500076'
group by serial_no
) B
where 1 = 1
and A.register_date = B.date
)BB
where 1=1
and AA.serial_no = BB.serial_no


not working or working 600 sec










share|improve this question
















decreasing running time (select query executing time)

even query is not working

it is reducing code line

there are 80 tables



select 
(ant_return_loss_pass='pass')+(ant_cross_isolation_pass='pass') as pass_count,
(ant_return_loss_pass='fail')+(ant_cross_isolation_pass='fail') as fail_count,
(ant_return_loss_pass='') +(ant_cross_isolation_pass='') as blank_count
from
(
select A.serial_no,
A.pass_fail as ant_return_loss_pass
from ant_return_loss A,
(
select max(register_date) as date
from ant_return_loss
where 1=1
and serial_no >= '184500074'
and serial_no <= '184500076'
group by serial_no
) B
where 1 = 1
and A.register_date = B.date
)AA
,(
select A.serial_no,
A.pass_fail as ant_cross_isolation_pass
from ant_cross_isolation A,
(
select max(register_date) as date
from ant_cross_isolation
where 1=1
and serial_no >= '184500074'
and serial_no <= '184500076'
group by serial_no
) B
where 1 = 1
and A.register_date = B.date
)BB
where 1=1
and AA.serial_no = BB.serial_no


not working or working 600 sec







mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 7:50









Armali

7,6501138106




7,6501138106










asked Jan 3 at 2:48









K KIMK KIM

204




204













  • What version of MySQL? Can you provide sample data? and expected results (based on the sample data)?

    – Used_By_Already
    Jan 3 at 4:16



















  • What version of MySQL? Can you provide sample data? and expected results (based on the sample data)?

    – Used_By_Already
    Jan 3 at 4:16

















What version of MySQL? Can you provide sample data? and expected results (based on the sample data)?

– Used_By_Already
Jan 3 at 4:16





What version of MySQL? Can you provide sample data? and expected results (based on the sample data)?

– Used_By_Already
Jan 3 at 4:16












1 Answer
1






active

oldest

votes


















1














The query below uses explicit join syntax and case expressions to make you query easier to understand:



SELECT
COUNT( CASE WHEN ant_return_loss_pass = 'pass' AND
ant_cross_isolation_pass = 'pass' THEN 1 END ) AS pass_count
, COUNT( CASE WHEN ant_return_loss_pass = 'fail' AND
ant_cross_isolation_pass = 'fail' THEN 1 END ) AS fail_count
, COUNT( CASE WHEN ant_return_loss_pass = '' AND
ant_cross_isolation_pass = '' THEN 1 END ) AS blank_count
FROM (
SELECT
A.serial_no
, A.pass_fail AS ant_return_loss_pass
FROM ant_return_loss A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date
) AA
INNER JOIN (
SELECT
A.serial_no
, A.pass_fail AS ant_cross_isolation_pass
FROM ant_cross_isolation A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_cross_isolation
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date
) BB ON AA.serial_no = BB.serial_no


To examine if this can be improved for performance however requires access to your database. For example do you indexes for ant_return_loss.serial_no or ant_cross_isolation.serial_no these will aid the where clauses of the subqueries.



Have you run any explain plans on the query? see: https://dev.mysql.com/doc/refman/5.7/en/explain.html



Note to avoid long running time you can use explain on separated portions of the overall query, look for indexes that may assist: e.g.



            explain
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no


then:



    explain
SELECT
A.serial_no
, A.pass_fail AS ant_return_loss_pass
FROM ant_return_loss A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date


until you have examined all portions for way to improve performance.






share|improve this answer
























  • well it doesn't work when there are tables over 8 ;( anyway thnx

    – K KIM
    Jan 3 at 8:27






  • 1





    what does that mean? what does not work? what is "tables over 8"? is that 8 tables? if the query you presented in the question is not the true query, how can anyone help on a query they have not seen?

    – Used_By_Already
    Jan 3 at 9:49













  • Have you attempted to examine any explain plans?

    – Used_By_Already
    Jan 3 at 9:51











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015699%2fhow-to-decrease-executing-select-query-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The query below uses explicit join syntax and case expressions to make you query easier to understand:



SELECT
COUNT( CASE WHEN ant_return_loss_pass = 'pass' AND
ant_cross_isolation_pass = 'pass' THEN 1 END ) AS pass_count
, COUNT( CASE WHEN ant_return_loss_pass = 'fail' AND
ant_cross_isolation_pass = 'fail' THEN 1 END ) AS fail_count
, COUNT( CASE WHEN ant_return_loss_pass = '' AND
ant_cross_isolation_pass = '' THEN 1 END ) AS blank_count
FROM (
SELECT
A.serial_no
, A.pass_fail AS ant_return_loss_pass
FROM ant_return_loss A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date
) AA
INNER JOIN (
SELECT
A.serial_no
, A.pass_fail AS ant_cross_isolation_pass
FROM ant_cross_isolation A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_cross_isolation
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date
) BB ON AA.serial_no = BB.serial_no


To examine if this can be improved for performance however requires access to your database. For example do you indexes for ant_return_loss.serial_no or ant_cross_isolation.serial_no these will aid the where clauses of the subqueries.



Have you run any explain plans on the query? see: https://dev.mysql.com/doc/refman/5.7/en/explain.html



Note to avoid long running time you can use explain on separated portions of the overall query, look for indexes that may assist: e.g.



            explain
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no


then:



    explain
SELECT
A.serial_no
, A.pass_fail AS ant_return_loss_pass
FROM ant_return_loss A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date


until you have examined all portions for way to improve performance.






share|improve this answer
























  • well it doesn't work when there are tables over 8 ;( anyway thnx

    – K KIM
    Jan 3 at 8:27






  • 1





    what does that mean? what does not work? what is "tables over 8"? is that 8 tables? if the query you presented in the question is not the true query, how can anyone help on a query they have not seen?

    – Used_By_Already
    Jan 3 at 9:49













  • Have you attempted to examine any explain plans?

    – Used_By_Already
    Jan 3 at 9:51
















1














The query below uses explicit join syntax and case expressions to make you query easier to understand:



SELECT
COUNT( CASE WHEN ant_return_loss_pass = 'pass' AND
ant_cross_isolation_pass = 'pass' THEN 1 END ) AS pass_count
, COUNT( CASE WHEN ant_return_loss_pass = 'fail' AND
ant_cross_isolation_pass = 'fail' THEN 1 END ) AS fail_count
, COUNT( CASE WHEN ant_return_loss_pass = '' AND
ant_cross_isolation_pass = '' THEN 1 END ) AS blank_count
FROM (
SELECT
A.serial_no
, A.pass_fail AS ant_return_loss_pass
FROM ant_return_loss A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date
) AA
INNER JOIN (
SELECT
A.serial_no
, A.pass_fail AS ant_cross_isolation_pass
FROM ant_cross_isolation A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_cross_isolation
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date
) BB ON AA.serial_no = BB.serial_no


To examine if this can be improved for performance however requires access to your database. For example do you indexes for ant_return_loss.serial_no or ant_cross_isolation.serial_no these will aid the where clauses of the subqueries.



Have you run any explain plans on the query? see: https://dev.mysql.com/doc/refman/5.7/en/explain.html



Note to avoid long running time you can use explain on separated portions of the overall query, look for indexes that may assist: e.g.



            explain
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no


then:



    explain
SELECT
A.serial_no
, A.pass_fail AS ant_return_loss_pass
FROM ant_return_loss A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date


until you have examined all portions for way to improve performance.






share|improve this answer
























  • well it doesn't work when there are tables over 8 ;( anyway thnx

    – K KIM
    Jan 3 at 8:27






  • 1





    what does that mean? what does not work? what is "tables over 8"? is that 8 tables? if the query you presented in the question is not the true query, how can anyone help on a query they have not seen?

    – Used_By_Already
    Jan 3 at 9:49













  • Have you attempted to examine any explain plans?

    – Used_By_Already
    Jan 3 at 9:51














1












1








1







The query below uses explicit join syntax and case expressions to make you query easier to understand:



SELECT
COUNT( CASE WHEN ant_return_loss_pass = 'pass' AND
ant_cross_isolation_pass = 'pass' THEN 1 END ) AS pass_count
, COUNT( CASE WHEN ant_return_loss_pass = 'fail' AND
ant_cross_isolation_pass = 'fail' THEN 1 END ) AS fail_count
, COUNT( CASE WHEN ant_return_loss_pass = '' AND
ant_cross_isolation_pass = '' THEN 1 END ) AS blank_count
FROM (
SELECT
A.serial_no
, A.pass_fail AS ant_return_loss_pass
FROM ant_return_loss A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date
) AA
INNER JOIN (
SELECT
A.serial_no
, A.pass_fail AS ant_cross_isolation_pass
FROM ant_cross_isolation A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_cross_isolation
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date
) BB ON AA.serial_no = BB.serial_no


To examine if this can be improved for performance however requires access to your database. For example do you indexes for ant_return_loss.serial_no or ant_cross_isolation.serial_no these will aid the where clauses of the subqueries.



Have you run any explain plans on the query? see: https://dev.mysql.com/doc/refman/5.7/en/explain.html



Note to avoid long running time you can use explain on separated portions of the overall query, look for indexes that may assist: e.g.



            explain
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no


then:



    explain
SELECT
A.serial_no
, A.pass_fail AS ant_return_loss_pass
FROM ant_return_loss A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date


until you have examined all portions for way to improve performance.






share|improve this answer













The query below uses explicit join syntax and case expressions to make you query easier to understand:



SELECT
COUNT( CASE WHEN ant_return_loss_pass = 'pass' AND
ant_cross_isolation_pass = 'pass' THEN 1 END ) AS pass_count
, COUNT( CASE WHEN ant_return_loss_pass = 'fail' AND
ant_cross_isolation_pass = 'fail' THEN 1 END ) AS fail_count
, COUNT( CASE WHEN ant_return_loss_pass = '' AND
ant_cross_isolation_pass = '' THEN 1 END ) AS blank_count
FROM (
SELECT
A.serial_no
, A.pass_fail AS ant_return_loss_pass
FROM ant_return_loss A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date
) AA
INNER JOIN (
SELECT
A.serial_no
, A.pass_fail AS ant_cross_isolation_pass
FROM ant_cross_isolation A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_cross_isolation
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date
) BB ON AA.serial_no = BB.serial_no


To examine if this can be improved for performance however requires access to your database. For example do you indexes for ant_return_loss.serial_no or ant_cross_isolation.serial_no these will aid the where clauses of the subqueries.



Have you run any explain plans on the query? see: https://dev.mysql.com/doc/refman/5.7/en/explain.html



Note to avoid long running time you can use explain on separated portions of the overall query, look for indexes that may assist: e.g.



            explain
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no


then:



    explain
SELECT
A.serial_no
, A.pass_fail AS ant_return_loss_pass
FROM ant_return_loss A
INNER JOIN (
SELECT MAX( register_date ) AS date
FROM ant_return_loss
WHERE serial_no >= '184500074'
AND serial_no <= '184500076'
GROUP BY serial_no
) B ON A.register_date = B.date


until you have examined all portions for way to improve performance.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 4:41









Used_By_AlreadyUsed_By_Already

23.1k22139




23.1k22139













  • well it doesn't work when there are tables over 8 ;( anyway thnx

    – K KIM
    Jan 3 at 8:27






  • 1





    what does that mean? what does not work? what is "tables over 8"? is that 8 tables? if the query you presented in the question is not the true query, how can anyone help on a query they have not seen?

    – Used_By_Already
    Jan 3 at 9:49













  • Have you attempted to examine any explain plans?

    – Used_By_Already
    Jan 3 at 9:51



















  • well it doesn't work when there are tables over 8 ;( anyway thnx

    – K KIM
    Jan 3 at 8:27






  • 1





    what does that mean? what does not work? what is "tables over 8"? is that 8 tables? if the query you presented in the question is not the true query, how can anyone help on a query they have not seen?

    – Used_By_Already
    Jan 3 at 9:49













  • Have you attempted to examine any explain plans?

    – Used_By_Already
    Jan 3 at 9:51

















well it doesn't work when there are tables over 8 ;( anyway thnx

– K KIM
Jan 3 at 8:27





well it doesn't work when there are tables over 8 ;( anyway thnx

– K KIM
Jan 3 at 8:27




1




1





what does that mean? what does not work? what is "tables over 8"? is that 8 tables? if the query you presented in the question is not the true query, how can anyone help on a query they have not seen?

– Used_By_Already
Jan 3 at 9:49







what does that mean? what does not work? what is "tables over 8"? is that 8 tables? if the query you presented in the question is not the true query, how can anyone help on a query they have not seen?

– Used_By_Already
Jan 3 at 9:49















Have you attempted to examine any explain plans?

– Used_By_Already
Jan 3 at 9:51





Have you attempted to examine any explain plans?

– Used_By_Already
Jan 3 at 9:51




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015699%2fhow-to-decrease-executing-select-query-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Mossoró

Error while reading .h5 file using the rhdf5 package in R

Pushsharp Apns notification error: 'InvalidToken'