12
How can I optimize the following code to not use 3 Selects and not plaster the query to only 3 status
(
SELECT *
FROM historico
WHERE
his_status = 'FRACASSO'
ORDER BY his_data DESC
LIMIT 50
)
UNION ALL
(
SELECT *
FROM historico
WHERE
his_status = 'REAVALIAR'
ORDER BY his_data DESC
LIMIT 50
)
UNION ALL
(
SELECT *
FROM historico
WHERE
his_status = 'SUCESSO'
ORDER BY his_data DESC
LIMIT 50
)
At the moment I have 2562 records in the historical table and I am using them all to train an RNA. It costs 3 to 4 minutes. This query will allow the user to indicate how many samples of each status you want to use. Quantity 50 is an example. Query optimization is also to decrease the cost of time.
Yes, it is valid to use in, as long as I inform the interval by the application, but it can only be used if the query is optimized. With only 1 select, at least.
– Billly Jow
I didn’t pay attention to the tripo limit , 50 of each case.
– Motta
Related: https://answall.com/q/254540/57801
– Don't Panic
An index talves help , using the same UNION , index his_data,his_status
– Motta
Normally UNION is a reasonable solution, dynamism can be produced in the client language (when available). Perhaps it was the case to use a function or precedent, but usually it is not justified.
– Bacco
Updated response.
– Sam