I had a query like this, that should be executed after each MySQL actions. This query is now slowing down page loading because the data increased, I did everything like proper indexing, but the query is still slow relatively.
Is there any other way to perform those checks?
$query = "
UPDATE {$tprefix}wh_profg
SET status =
CASE
WHEN
batchno in (
select
batchno
from
{$tprefix}wh_profulldetail
where
remainingdays <= 0
)
THEN
'expired'
WHEN
QC = 'rejected' and QA != 'rejected'
and status != 'expired'
THEN
'QC-rejected'
WHEN
QA = 'rejected' and QC != 'rejected'
and status != 'expired'
THEN
'QA-rejected'
WHEN
QA = 'rejected' and QC = 'rejected'
and status != 'expired'
THEN
'QA&QC-rejected'
WHEN
(
batchno in (
select
batchno
from
{$tprefix}wh_profulldetail
where
available <= 0
)
) and status != 'expired'
and status NOT LIKE '%rejected'
THEN
'empty'
WHEN
QC ='quarantine' and status != 'empty'
and status != 'expired' and
batchno in (
select
batchno
from
{$tprefix}wh_profulldetail
where
available > 0 and remainingdays > 0
)
THEN
'quarantine'
WHEN
QC ='approved' and QA = 'approved'
and status != 'empty' and status != 'expired'
and status NOT LIKE '%rejected' and
batchno in (
select
batchno
from
{$tprefix}wh_profulldetail
where
available > 0 and remainingdays > 0
)
THEN
'available'
ELSE
'unknown'
END
";
wh_profg
is the main table, andwh_profulldetail
is view of that table and other tablewh_profg_usage
(its complicated query). – Cutpursecan there be multiple rows with the same batchno
yes. – Cutpurse