Subject: Discarding the resulting rows

From: "Murali M. Krishna" <[email-masked]>
Date: Mon, 26 Apr 2010 10:43:26 -0700 (PDT)

Hello Hackers:

Two questions.

1.

I would like to execute queries such as 

select * from part and time the query. But I want to ignore how much time is taken for printing the result to a file or the screen.

Basically, I would like to discard the result rows after doing all the work required to execute the query.

I looked at the documentation and I saw something about using the keyword PERFORM rather than SELECT.

I tried PERFORM * from part; 

But this gave me a syntax error.

Please let me know how this can be done.

2.

How do I clear the buffer caches between two query runs?
I believe this is not possible in Postgres. Can someone please confirm this or tell me how it may be done.

Thanks,

Murali.

-----------------------------------------------------------------
Please visit NumberFest.com for educational number puzzles & mind exercises for all ages! And please tell your friends about it. Thank You!

---

From: "Kevin Grittner" <[email-masked]>
Date: Mon, 26 Apr 2010 14:36:02 -0500

> the work required to execute the query.
 
I would use EXPLAIN ANALYZE SELECT ...
 
> keyword PERFORM rather than SELECT.
 
I don't remember ever seeing anything like that.  Do you have a URL?
 
> How do I clear the buffer caches between two query runs?
 
The easiest way to clear the PostgreSQL cache is to restart the
service.  PostgreSQL goes through the OS cache; so you'll need to
clear that, too.  How you do that is dependent on your OS.  Of
course, in most real use cases, a significant portion of the
database would be cached, so unless you're dealing with a very
unusual situation, it's hard to see what the value would be of such
a benchmark, unless you're trying to create an artificial "worst
case" scenario for bounding purposes.
 
Oh, and most serious database servers have 256MB or more of battery
backed cache on the RAID controller; don't forget to deal with that
somehow.
 
-Kevin

---

From: Jaime Casanova <[email-masked]>
Date: Mon, 26 Apr 2010 14:49:16 -0500

> I don't remember ever seeing anything like that.  Do you have a URL?

i guess he is refering to the plpgsql's PERFORM statement, which of
course he can't use outside a plpgsql function...
mmm... well, IIRC, in 9.0 he will be able to do DO $$ PERFORM * FROM
tabla; $$ LANGUAGE plpgsql;

but i think DO is not an EXPLAINing statement

-- 
Atentamente,
Jaime Casanova
Soporte y capacitación de PostgreSQL
Asesoría y desarrollo de sistemas
Guayaquil - Ecuador
Cel. +59387171157

---

From: Robert Haas <[email-masked]>
Date: Mon, 26 Apr 2010 16:03:52 -0400

> I would use EXPLAIN ANALYZE SELECT ...

There's some overhead to that, of course.

....Robert

---

From: Jaime Casanova <[email-masked]>
Date: Mon, 26 Apr 2010 15:16:01 -0500

> There's some overhead to that, of course.

he could see the "actual time" in the very first row of the EXPLAIN
ANALYZE... isn't that a value that is more close to what the OP is
looking for?

---

From: "Kevin Grittner" <[email-masked]>
Date: Mon, 26 Apr 2010 15:24:02 -0500

Robert Haas <[email-masked]> wrote:
>>> Basically, I would like to discard the result rows after doing
>>> all the work required to execute the query.
>>
 
Good point.  At the moment I can't think how to do better, though.
 
Other suggestions, anyone?
 
-Kevin

---

From: Tom Lane <[email-masked]>
Date: Mon, 26 Apr 2010 16:25:35 -0400

> ANALYZE... isn't that a value that is more close to what the OP is

Well, it will include the instrumentation overhead of EXPLAIN ANALYZE,
which can be nontrivial depending on your hardware and the query plan.

On the other hand, EXPLAIN skips the cost of converting the result data
to text form, not to mention the network overhead of delivering it; so
in another sense it's underestimating the work involved.

I guess the real question is exactly what the OP is hoping to measure
and why.

			regards, tom lane

---

From: "Murali M. Krishna" <[email-masked]>
Date: Mon, 26 Apr 2010 16:40:48 -0700 (PDT)

Hello All:

The optimizer assumes that data is disk resident when computing the cost of a query plan.
I am trying to ascertain what the correlation is between times and costs of some benchmark queries to see how good the cost model is.

Since I have more than 100 queries, it would be painful to stop and start the server each time to force all the buffer pages out. Also, some of these queries have large number of result rows. I don't want the time to be skewed by the output time.

Cheers,

Murali.

--- On Mon, 4/26/10, Tom Lane <[email-masked]> wrote:

From: Tom Lane <[email-masked]>
Subject: Re: [HACKERS] Discarding the resulting rows
To: "Jaime Casanova" <[email-masked]>
Cc: "Robert Haas" <[email-masked]>, "Kevin Grittner" <[email-masked]>, [email-masked], "Murali M. Krishna" <[email-masked]>
Date: Monday, April 26, 2010, 1:25 PM

            regards, tom lane

-- 
Sent via pgsql-hackers mailing list ([email-masked])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers