refs #6784 Delete unnecessary JOINs
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Ivan Mas 2024-02-22 14:01:19 +01:00
parent 65cb2d45fd
commit a0cb32ea10
4 changed files with 11 additions and 9 deletions

View File

@ -47,12 +47,11 @@ BEGIN
JOIN itemCategory ic ON ic.id = tp.categoryFk
JOIN ticket t ON t.id = s.ticketFk
JOIN client c ON c.id = t.clientFk
JOIN clientType ct ON ct.code = c.typeFk
JOIN warehouse w ON w.id = t.warehouseFk
JOIN address ad ON ad.id = t.addressFk
LEFT JOIN province p ON p.id = ad.provinceFk
WHERE tm.period BETWEEN vMaxPeriod AND vPeriod
AND ct.code <> 'loses'
AND c.typeFk <> 'loses'
AND NOT w.code = 'inv'
GROUP BY p.countryFk, s.itemFk, tm.period, t.warehouseFk;
END IF;

View File

@ -44,10 +44,9 @@ proc:BEGIN
LEFT JOIN saleTracking st ON st.saleFk = s.id
JOIN ticket t ON t.id = s.ticketFk
JOIN client c on c.id = t.clientFk
JOIN clientType ct ON ct.code = c.typeFk
WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE())
AND st.saleFk IS NULL
AND ct.code IN ('normal', 'trust')
AND c.typeFk IN ('normal', 'trust')
GROUP BY s.itemFk
) sub2 ON sub2.itemFk = sub.itemFk
UNION ALL
@ -70,10 +69,9 @@ proc:BEGIN
LEFT JOIN saleTracking st ON st.saleFk = s.id
JOIN ticket t ON t.id = s.ticketFk
JOIN client c on c.id = t.clientFk
JOIN clientType ct ON ct.code = c.typeFk
WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE())
AND st.saleFk IS NULL
AND ct.code IN ('normal', 'trust')
AND c.typeFk IN ('normal', 'trust')
GROUP BY s.itemFk
) sub5 ON sub5.itemFk = v.item_id
WHERE v.calc_id = vCalcVisibleFk

View File

@ -120,7 +120,7 @@ BEGIN
TRUE,
s.id,
st.`order`,
ct.`code`,
c.typeFk,
cb.claimFk,
NULL
FROM sale s
@ -128,7 +128,6 @@ BEGIN
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
LEFT JOIN state st ON st.`code` = ts.`code`
JOIN client c ON c.id = t.clientFk
JOIN clientType ct ON ct.code = c.typeFk
JOIN state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
'DELIVERED',
IF (t.shipped > util.dayEnd(util.VN_CURDATE()),

View File

@ -41,7 +41,13 @@ module.exports = Self => {
include: {
relation: 'client',
scope: {
fields: ['id', 'typeFk']
fields: ['id', 'typeFk'],
include: {
relation: 'type',
scope: {
fields: ['code', 'description']
}
}
}
}
},