B
B
beduin012021-01-14 10:56:24
PostgreSQL
beduin01, 2021-01-14 10:56:24

Why does the query take 10 times longer to complete?

Accidentally typoed and instead of: it turned out:
SELECT * FROM files WHERE parsing_status IS NULL

SELECT * FROM files WHERE  parsing_status IS NULL AND parsing_status IS NULL

As a result, instead of 1 second, the request worked 10 times longer.

The request itself is a little more complicated than the specified one, but the essence was precisely in duplicating the specified field. How can this be? At least theoretically?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
igaraev, 2021-01-14
@igaraev

It is necessary to look at the request plan.

S
Sergey Vodakov, 2021-01-14
@WaterSmith

Just a guess:
It looks like you're doing a Cartesian product of the files table, as if you joined the table to itself without a condition. As a result, the selection occurs by the square of the number of records, i.e. instead of 10 records, 100 will be processed, and instead of 1000 - 1000000.

D
d-stream, 2021-01-14
@d-stream

I would venture to suggest that the oversimplification of the typo hides important details.
Still, it is worth giving samples of two complete queries (well, and then, apparently, the structure of index tables)
Naturally, if the experiment is repeated - 10 times out of 10 in any order, the ratio of execution time is preserved.
And by itself after comparison of plans of execution of these requests.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question