Answer the question
In order to leave comments, you need to log in
Why SQL query is executed at different speed?
There is a request:
SELECT COUNT(*) FROM xml_files t1
WHERE NOT EXISTS (SELECT 1
FROM xml_files t2
WHERE t1."id" = t2."id" AND
t1."mydate" < t2."mydate"
)
AND t1.insert_status IS NULL
AND t1.section_name='users' AND t1.region IN ('Moscow') AND t1.xml_date >= to_date('2016', 'YYYY') AND t1.parsing_status IS NULL
Answer the question
In order to leave comments, you need to log in
When I execute this query in SQL, then 10 times it can be executed for 90 seconds, and for 11 times it can be completed in 5 and then continue to be executed in 5.
...
Are there any optimizers in the database or other tricky logic? Just after an hour, history repeats itself and the request starts to run slowly again.
SELECT * FROM (
SELECT row_number() OVER (PARTITION BY id ORDER BY mydate DESC) as rn,
t1.* FROM xml_files t1
AND t1.insert_status IS NULL
AND t1.section_name='users' AND t1.region IN ('Moscow') AND t1.xml_date >= to_date('2016', 'YYYY') AND t1.parsing_status IS NULL
) t
WHERE rn = 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question