G
G
galithr2017-02-23 14:22:38
PostgreSQL
galithr, 2017-02-23 14:22:38

How to speed up RETURN QUERY EXECUTE?

I'm just making a request

SELECT "id", "name" FROM "mytable" WHERE date BETWEEN '2017-02-01 00:00:00'  AND '2017-02-22 00:00:00'

the request is processed in 1.7 seconds (there is a lot of data),
I put the same request in a function in which I make the same request like this:
RETURN QUERY EXECUTE 'SELECT "id", "name" FROM "mytable" WHERE date BETWEEN ' || quote_nullable(t1) || '  AND ' || quote_nullable(t2);

request speed is halved to 3.4 seconds. How can this be? yes, certain actions are done in the function, but they are performed in fractions of seconds

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Melkij, 2017-02-23
@melkij

Why is query execute here? The request is static.
However, there is generally nothing to plan for 1.7s, so these are matches.
In general, the storage call materializes. The working hypothesis is that you spend time on materialization. What happens next with the data? Do you see anything useful in explain? (for a long time I didn’t disassemble the storage, I don’t remember what gets there)

D
Dmitry, 2017-11-01
@totalcount

What does the trace say?

M
Maksim Herasim, 2017-11-02
@Tkreks

Now I don’t use Google, but maybe the problem is in the firewall, which is enabled by default for instances and in which you need to set up allowing rules?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question