<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<id>tag:www.nabble.com,2006:forum-774</id>
	<title>Nabble - PostgreSQL - performance</title>
	<updated>2008-11-21T15:01:41Z</updated>
	<link rel="self" type="application/atom+xml" href="http://www.nabble.com/PostgreSQL---performance-f774.xml" />
	<link rel="alternate" type="text/html" href="http://www.nabble.com/PostgreSQL---performance-f774.html" />
	<subtitle type="html"></subtitle>
	
<entry>
	<id>tag:www.nabble.com,2006:post-20631096</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T15:01:41Z</published>
	<updated>2008-11-21T15:01:41Z</updated>
	<author>
		<name>Scott Carey</name>
	</author>
	<content type="html">If Autovacuum was working, and your tables still got very bloated, it may be because your free space map is not configured large enough.
&lt;br&gt;What is your value for max_fsm_pages?
&lt;br&gt;&lt;br&gt;The effect of having max_fsm_pages or max_fsm_relations too small is bloating of tables and indexes.
&lt;br&gt;&lt;br&gt;Increasing it too large will not use a lot of memory. &amp;nbsp;Since you had over 130000 free pages in just one table below, make sure it is set to at least 150000. &amp;nbsp;This may be overkill with regular vacuum or autovacuum, however its much better to have this too large than too small.
&lt;br&gt;&lt;br&gt;Your server has 2GB of RAM? &amp;nbsp;You should make sure your shared_buffers is between 100MB and 400MB if this is a dedicated server, or more in some cases.
&lt;br&gt;&lt;br&gt;If you can, plan to migrate to 8.3 (or 8.4 early next year). &amp;nbsp;Vacuum, bloating, and configuration related to these have improved a great deal since 8.1.
&lt;br&gt;&lt;br&gt;Although your Indexes below remain bloated, the fact that they have been vacuumed, combined with a large enough value set in max_fsm_pages, means that they should not get any larger. &amp;nbsp;I am not sure how to foce these to be smaller.
&lt;br&gt;The larger size, after a vacuum and large enough max_fsm_pages value will also not cause a performance problem. &amp;nbsp;It will waste some disk space and be a bit slower to access, but only very slightly.
&lt;br&gt;&lt;br&gt;&lt;br&gt;-----Original Message-----
&lt;br&gt;From: &lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20631096&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance-owner@...&lt;/a&gt; [mailto:&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20631096&amp;i=1&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance-owner@...&lt;/a&gt;] On Behalf Of Andrus
&lt;br&gt;Sent: Friday, November 21, 2008 1:51 PM
&lt;br&gt;To: Richard Huxton
&lt;br&gt;Cc: PFC; &lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20631096&amp;i=2&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;
&lt;br&gt;Subject: Re: [PERFORM] Hash join on int takes 8..114 seconds
&lt;br&gt;&lt;br&gt;&amp;gt; If it's not a million rows, then the table is bloated. Try (as postgres
&lt;br&gt;&amp;gt; or some other db superuser) &amp;quot;vacuum full pg_shdepend&amp;quot; and a &amp;quot;reindex
&lt;br&gt;&amp;gt; pg_shdepend&amp;quot;.
&lt;br&gt;&lt;br&gt;reindex table pg_shdepend causes error
&lt;br&gt;&lt;br&gt;ERROR: &amp;nbsp;shared table &amp;quot;pg_shdepend&amp;quot; can only be reindexed in stand-alone mode
&lt;br&gt;&lt;br&gt;vacuum full verbose pg_shdepend seems to work but indexes are still bloated.
&lt;br&gt;How to remove index bloat ?
&lt;br&gt;&lt;br&gt;sizes after vacuum full are below.
&lt;br&gt;pg_shdepend &amp;nbsp;size 1234 MB includes its index sizes, so indexes are 100%
&lt;br&gt;bloated.
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1214 pg_catalog.pg_shdepend &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1234 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1232 pg_catalog.pg_shdepend_depender_index &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 795 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1233 pg_catalog.pg_shdepend_reference_index &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;439 MB
&lt;br&gt;&lt;br&gt;Andrus.
&lt;br&gt;&lt;br&gt;&lt;br&gt;vacuum full verbose pg_shdepend;
&lt;br&gt;&lt;br&gt;INFO: &amp;nbsp;vacuuming &amp;quot;pg_catalog.pg_shdepend&amp;quot;
&lt;br&gt;INFO: &amp;nbsp;&amp;quot;pg_shdepend&amp;quot;: found 254 removable, 3625 nonremovable row versions in
&lt;br&gt;131517 pages
&lt;br&gt;DETAIL: &amp;nbsp;0 dead row versions cannot be removed yet.
&lt;br&gt;Nonremovable row versions range from 49 to 49 bytes long.
&lt;br&gt;There were 16115259 unused item pointers.
&lt;br&gt;Total free space (including removable row versions) is 1010091872 bytes.
&lt;br&gt;131456 pages are or will become empty, including 8 at the end of the table.
&lt;br&gt;131509 pages containing 1010029072 free bytes are potential move
&lt;br&gt;destinations.
&lt;br&gt;CPU 2.08s/0.92u sec elapsed 63.51 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;pg_shdepend_depender_index&amp;quot; now contains 3625 row versions in
&lt;br&gt;101794 pages
&lt;br&gt;DETAIL: &amp;nbsp;254 index row versions were removed.
&lt;br&gt;101611 index pages have been deleted, 20000 are currently reusable.
&lt;br&gt;CPU 0.87s/0.28u sec elapsed 25.44 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;pg_shdepend_reference_index&amp;quot; now contains 3625 row versions in
&lt;br&gt;56139 pages
&lt;br&gt;DETAIL: &amp;nbsp;254 index row versions were removed.
&lt;br&gt;56076 index pages have been deleted, 20000 are currently reusable.
&lt;br&gt;CPU 0.51s/0.15u sec elapsed 23.10 sec.
&lt;br&gt;INFO: &amp;nbsp;&amp;quot;pg_shdepend&amp;quot;: moved 1518 row versions, truncated 131517 to 25 pages
&lt;br&gt;DETAIL: &amp;nbsp;CPU 5.26s/2.39u sec elapsed 89.93 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;pg_shdepend_depender_index&amp;quot; now contains 3625 row versions in
&lt;br&gt;101794 pages
&lt;br&gt;DETAIL: &amp;nbsp;1518 index row versions were removed.
&lt;br&gt;101609 index pages have been deleted, 20000 are currently reusable.
&lt;br&gt;CPU 0.94s/0.28u sec elapsed 24.61 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;pg_shdepend_reference_index&amp;quot; now contains 3625 row versions in
&lt;br&gt;56139 pages
&lt;br&gt;DETAIL: &amp;nbsp;1518 index row versions were removed.
&lt;br&gt;56088 index pages have been deleted, 20000 are currently reusable.
&lt;br&gt;CPU 0.54s/0.14u sec elapsed 21.11 sec.
&lt;br&gt;&lt;br&gt;Query returned successfully with no result in 253356 ms
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;--
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20631096&amp;i=3&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20631096&amp;i=4&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20631096.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20630137</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T13:51:24Z</published>
	<updated>2008-11-21T13:51:24Z</updated>
	<author>
		<name>Andrus Moor-2</name>
	</author>
	<content type="html">&amp;gt; If it's not a million rows, then the table is bloated. Try (as postgres
&lt;br&gt;&amp;gt; or some other db superuser) &amp;quot;vacuum full pg_shdepend&amp;quot; and a &amp;quot;reindex
&lt;br&gt;&amp;gt; pg_shdepend&amp;quot;.
&lt;br&gt;&lt;br&gt;reindex table pg_shdepend causes error
&lt;br&gt;&lt;br&gt;ERROR: &amp;nbsp;shared table &amp;quot;pg_shdepend&amp;quot; can only be reindexed in stand-alone mode
&lt;br&gt;&lt;br&gt;vacuum full verbose pg_shdepend seems to work but indexes are still bloated.
&lt;br&gt;How to remove index bloat ?
&lt;br&gt;&lt;br&gt;sizes after vacuum full are below.
&lt;br&gt;pg_shdepend &amp;nbsp;size 1234 MB includes its index sizes, so indexes are 100% 
&lt;br&gt;bloated.
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1214 pg_catalog.pg_shdepend &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1234 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1232 pg_catalog.pg_shdepend_depender_index &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 795 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1233 pg_catalog.pg_shdepend_reference_index &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;439 MB
&lt;br&gt;&lt;br&gt;Andrus.
&lt;br&gt;&lt;br&gt;&lt;br&gt;vacuum full verbose pg_shdepend;
&lt;br&gt;&lt;br&gt;INFO: &amp;nbsp;vacuuming &amp;quot;pg_catalog.pg_shdepend&amp;quot;
&lt;br&gt;INFO: &amp;nbsp;&amp;quot;pg_shdepend&amp;quot;: found 254 removable, 3625 nonremovable row versions in 
&lt;br&gt;131517 pages
&lt;br&gt;DETAIL: &amp;nbsp;0 dead row versions cannot be removed yet.
&lt;br&gt;Nonremovable row versions range from 49 to 49 bytes long.
&lt;br&gt;There were 16115259 unused item pointers.
&lt;br&gt;Total free space (including removable row versions) is 1010091872 bytes.
&lt;br&gt;131456 pages are or will become empty, including 8 at the end of the table.
&lt;br&gt;131509 pages containing 1010029072 free bytes are potential move 
&lt;br&gt;destinations.
&lt;br&gt;CPU 2.08s/0.92u sec elapsed 63.51 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;pg_shdepend_depender_index&amp;quot; now contains 3625 row versions in 
&lt;br&gt;101794 pages
&lt;br&gt;DETAIL: &amp;nbsp;254 index row versions were removed.
&lt;br&gt;101611 index pages have been deleted, 20000 are currently reusable.
&lt;br&gt;CPU 0.87s/0.28u sec elapsed 25.44 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;pg_shdepend_reference_index&amp;quot; now contains 3625 row versions in 
&lt;br&gt;56139 pages
&lt;br&gt;DETAIL: &amp;nbsp;254 index row versions were removed.
&lt;br&gt;56076 index pages have been deleted, 20000 are currently reusable.
&lt;br&gt;CPU 0.51s/0.15u sec elapsed 23.10 sec.
&lt;br&gt;INFO: &amp;nbsp;&amp;quot;pg_shdepend&amp;quot;: moved 1518 row versions, truncated 131517 to 25 pages
&lt;br&gt;DETAIL: &amp;nbsp;CPU 5.26s/2.39u sec elapsed 89.93 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;pg_shdepend_depender_index&amp;quot; now contains 3625 row versions in 
&lt;br&gt;101794 pages
&lt;br&gt;DETAIL: &amp;nbsp;1518 index row versions were removed.
&lt;br&gt;101609 index pages have been deleted, 20000 are currently reusable.
&lt;br&gt;CPU 0.94s/0.28u sec elapsed 24.61 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;pg_shdepend_reference_index&amp;quot; now contains 3625 row versions in 
&lt;br&gt;56139 pages
&lt;br&gt;DETAIL: &amp;nbsp;1518 index row versions were removed.
&lt;br&gt;56088 index pages have been deleted, 20000 are currently reusable.
&lt;br&gt;CPU 0.54s/0.14u sec elapsed 21.11 sec.
&lt;br&gt;&lt;br&gt;Query returned successfully with no result in 253356 ms
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20630137&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20630137.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20629747</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T13:22:55Z</published>
	<updated>2008-11-21T13:22:55Z</updated>
	<author>
		<name>tv-8</name>
	</author>
	<content type="html">&lt;div class='shrinkable-quote'&gt;&amp;gt; 2. Run the following commands periodically in this order:
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; VACUUM FULL;
&lt;br&gt;&amp;gt; vacuum full pg_shdepend;
&lt;br&gt;&amp;gt; CLUSTER rid on (toode);
&lt;br&gt;&amp;gt; CLUSTER dok &amp;nbsp;on (kuupaev);
&lt;br&gt;&amp;gt; REINDEX DATABASE mydb;
&lt;br&gt;&amp;gt; REINDEX SYSTEM mydb;
&lt;br&gt;&amp;gt; ANALYZE;
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; Are all those command required or can something leaved out ?
&lt;/div&gt;&lt;br&gt;Running CLUSTER after VACUUM FULL is just a waste of time. In my 
&lt;br&gt;experience CLUSTER is actually faster in case of such heavily bloated 
&lt;br&gt;tables - I think this is caused by the fact that it creates indexes from 
&lt;br&gt;the beginning instead of updating them (as VACUUM FULL does).
&lt;br&gt;&lt;br&gt;So CLUSTER actually performs REINDEX, so I'd just run
&lt;br&gt;&lt;br&gt;CLUSTER rid ON rid_pkey;
&lt;br&gt;CLUSTER dok ON dok_pkey;
&lt;br&gt;ANALYZE rid;
&lt;br&gt;ANALYZE dok;
&lt;br&gt;&lt;br&gt;Clustering by other indexes might give better performance, using primary 
&lt;br&gt;keys is just a safe guess here. This should improve the performance of 
&lt;br&gt;your query and it seems these two tables are the most bloated ones.
&lt;br&gt;&lt;br&gt;I wouldn't do the same maintenance on the other tables now - it's just a 
&lt;br&gt;waste of time.
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt;&amp;gt; Several other things to consider:
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; 1) Regarding the toode column - why are you using CHAR(20) when the 
&lt;br&gt;&amp;gt;&amp;gt; values
&lt;br&gt;&amp;gt;&amp;gt; are actually shorter? This may significantly increase the amount of space
&lt;br&gt;&amp;gt;&amp;gt; required.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; There may be some products whose codes may be up to 20 characters.
&lt;br&gt;&amp;gt; PostgreSQL does not hold trailing spaces in db, so this does *not* 
&lt;br&gt;&amp;gt; affect to
&lt;br&gt;&amp;gt; space.
&lt;/div&gt;&lt;br&gt;OK, I haven't realized this. You're right.
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt;&amp;gt; 2) I've noticed the CPU used is Celeron, which may negatively affect the
&lt;br&gt;&amp;gt;&amp;gt; speed of hash computation. I'd try to replace it by something faster - 
&lt;br&gt;&amp;gt;&amp;gt; say
&lt;br&gt;&amp;gt;&amp;gt; INTEGER as an artificial primary key of the &amp;quot;toode&amp;quot; table and using it as
&lt;br&gt;&amp;gt;&amp;gt; a FK in other tables. &amp;nbsp;This might improve the &amp;quot;Bitmap Heap Scan on rid&amp;quot;
&lt;br&gt;&amp;gt;&amp;gt; part, but yes - it's just a minor improvement compared to the &amp;quot;Hash Join&amp;quot;
&lt;br&gt;&amp;gt;&amp;gt; part of the query.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; Natural key Toode CHAR(20) is used widely in different queries. 
&lt;br&gt;&amp;gt; Replacing it with INT surrogate key requires major application rewrite.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; Should I add surrogate index INT columns to toode and rid table and measure
&lt;br&gt;&amp;gt; test query speed in this case?
&lt;/div&gt;&lt;br&gt;Test it. Create tables with fake data, and compare the performance with 
&lt;br&gt;and without the surrogate keys. Using a simple data type instead of text 
&lt;br&gt;&amp;nbsp; gave me huge performance boost. For example one of my colleagues used 
&lt;br&gt;VARCHAR(15) to store IP addresses, and then used them to join tables 
&lt;br&gt;(and suffered by the poor perfomance). Replacing them by INET improved 
&lt;br&gt;the speed by several orders of magnitude.
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt;&amp;gt; Materialized views seem like a good idea to me, but maybe I'm not seeing
&lt;br&gt;&amp;gt;&amp;gt; something. What do you mean by &amp;quot;reports are different&amp;quot;? If there is a lot
&lt;br&gt;&amp;gt;&amp;gt; of rows for a given product / day, then creating an aggregated table with
&lt;br&gt;&amp;gt;&amp;gt; (product code / day) as a primary key is quite simple. It may require a
&lt;br&gt;&amp;gt;&amp;gt; lot of disk space, but it'll remove the hash join overhead. But if the
&lt;br&gt;&amp;gt;&amp;gt; queries are very different, then it may be difficult to build such
&lt;br&gt;&amp;gt;&amp;gt; materialized view(s).
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; log file seems that mostly only those queries are slow:
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; SELECT ...
&lt;br&gt;&amp;gt; &amp;nbsp; FROM dok JOIN rid USING (dokumnr)
&lt;br&gt;&amp;gt; &amp;nbsp; JOIN ProductId USING (ProductId)
&lt;br&gt;&amp;gt; &amp;nbsp; WHERE rid.ProductId LIKE :p1 || '%' AND dok.SaleDate&amp;gt;=:p2
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; :p1 and :p2 are parameters different for different queries.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; dok contains several years of data. :p2 is usually only few previous months
&lt;br&gt;&amp;gt; or last year ago.
&lt;br&gt;&amp;gt; SELECT column list contains fixed list of known columns from all tables.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; How to create index or materialized view to optimize this types of 
&lt;br&gt;&amp;gt; queries ?
&lt;/div&gt;&lt;br&gt;Well, difficult to answer without detailed information about the queries 
&lt;br&gt;you want to run, aggregated values, etc. Materialized views is a world 
&lt;br&gt;on it's own, and the best solution depends on (for example):
&lt;br&gt;&lt;br&gt;1) what aggregated values are you interested in (additive values are the
&lt;br&gt;&amp;nbsp; &amp;nbsp; most primitive ones, while VARIANCE etc. make it difficult)
&lt;br&gt;&lt;br&gt;2) do you need current data, or is it OK that today's data are not
&lt;br&gt;&amp;nbsp; &amp;nbsp; available till midnight (for example)?
&lt;br&gt;&lt;br&gt;Another thing you have to consider is whether you want to create 
&lt;br&gt;materialized view with final or intermediary data and then compute the 
&lt;br&gt;final data somehow (for example monthly totals from daily totals).
&lt;br&gt;&lt;br&gt;The most primitive (but often sufficient) solution is recreating the 
&lt;br&gt;materialized view periodically (for example every midnight). In your 
&lt;br&gt;case it'd mean running something like
&lt;br&gt;&lt;br&gt;CREATE TABLE materialized_view AS SELECT ... your query here ...
&lt;br&gt;GROUP BY productId, saleDate
&lt;br&gt;&lt;br&gt;This gives you daily totals for each product - the clients then can run 
&lt;br&gt;another query to compute the final data.
&lt;br&gt;&lt;br&gt;But of course, if you need to maintain 'current' data, you may create a 
&lt;br&gt;set of triggers to update the materialized view. Either after each 
&lt;br&gt;modification or (more sophisticated) when it's needed.
&lt;br&gt;&lt;br&gt;See for example a great presentation from this year's PGCon:
&lt;br&gt;&lt;br&gt;&lt;a href=&quot;http://www.pgcon.org/2008/schedule/events/69.en.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.pgcon.org/2008/schedule/events/69.en.html&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;regards
&lt;br&gt;Tomas
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20629747&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20629747.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20629240</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T12:48:21Z</published>
	<updated>2008-11-21T12:48:21Z</updated>
	<author>
		<name>tv-8</name>
	</author>
	<content type="html">&amp;gt; Thank you.
&lt;br&gt;&amp;gt; My 8.1.4 postgresql.conf does not contain such option. So 
&lt;br&gt;&amp;gt; vacuum_cost_delay is off probably.
&lt;br&gt;&amp;gt; Since doc does not recommend any value, I planned to use 2000
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; Will value of 30 allow other clients to work when VACUUM FULL is running ?
&lt;br&gt;&lt;br&gt;No, as someone already noted the VACUUM FULL is blocking anyway (and 
&lt;br&gt;does not use this value at all).
&lt;br&gt;&lt;br&gt;&amp;gt; Uncommented relevant values in postgresql.conf file are:
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; shared_buffers = 15000
&lt;br&gt;&amp;gt; work_mem = 512
&lt;br&gt;&lt;br&gt;I'd consider increasing this value a little - 0.5 MB seems too low to me 
&lt;br&gt;(but not necessarily).
&lt;br&gt;&lt;br&gt;&amp;gt; maintenance_work_mem = 131072
&lt;br&gt;&amp;gt; fsync = on
&lt;br&gt;&amp;gt; effective_cache_size= 70000
&lt;br&gt;&lt;br&gt;Well, your server has 2GB of RAM and usually it's recommended to set 
&lt;br&gt;this value to about 60-70% of your RAM, so using 540MB (25%) seems quite 
&lt;br&gt;low. Anyway this is just a hint to PostgreSQL, it does not increase 
&lt;br&gt;memory consumption or so - it's just an estimate of how much data are 
&lt;br&gt;cached by kernel.
&lt;br&gt;&lt;br&gt;Anyway, I don't expect these values have significant effect in case of 
&lt;br&gt;the issue solved in this thread.
&lt;br&gt;&lt;br&gt;regards
&lt;br&gt;Tomas
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20629240&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20629240.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20628844</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T12:20:36Z</published>
	<updated>2008-11-21T12:20:36Z</updated>
	<author>
		<name>Alvaro Herrera-7</name>
	</author>
	<content type="html">Andrus wrote:
&lt;br&gt;&lt;br&gt;&amp;gt;&amp;gt; So I gather you're not doing any vacuuming, eh?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Log files for every day are full of garbage messages below.
&lt;br&gt;&amp;gt; So I hope that vacuum is running well, isn't it ?
&lt;br&gt;&lt;br&gt;This does not really mean that autovacuum has done anything in the
&lt;br&gt;databases. &amp;nbsp;If the times are consistently separated by 1 min, then it's
&lt;br&gt;possible that it always exits without doing anything.
&lt;br&gt;&lt;br&gt;In such old a release we didn't have any decent logging mechanism in
&lt;br&gt;autovacuum :-( &amp;nbsp;You can change log_min_messages to debug2 to see if it
&lt;br&gt;actually does anything or not.
&lt;br&gt;&lt;br&gt;I suggest you connect to the problem database (and then to all others,
&lt;br&gt;just to be sure) and run &amp;quot;vacuum&amp;quot; (no full).
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Alvaro Herrera &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;a href=&quot;http://www.CommandPrompt.com/&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.CommandPrompt.com/&lt;/a&gt;&lt;br&gt;PostgreSQL Replication, Consulting, Custom Development, 24x7 support
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20628844&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20628844.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20628713</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T12:08:45Z</published>
	<updated>2008-11-21T12:08:45Z</updated>
	<author>
		<name>Andrus Moor-2</name>
	</author>
	<content type="html">Alvaro,
&lt;br&gt;&lt;br&gt;&amp;gt; 1. vacuum_cost_delay does not affect vacuum full
&lt;br&gt;&amp;gt; 2. vacuum full is always blocking, regardless of settings
&lt;br&gt;&lt;br&gt;So only way is to disable other database acces if vacuum full is required.
&lt;br&gt;&lt;br&gt;&amp;gt; So I gather you're not doing any vacuuming, eh?
&lt;br&gt;&lt;br&gt;Log files for every day are full of garbage messages below.
&lt;br&gt;So I hope that vacuum is running well, isn't it ?
&lt;br&gt;&lt;br&gt;Andrus.
&lt;br&gt;&lt;br&gt;2008-11-19 00:00:48 EET &amp;nbsp; &amp;nbsp;11728 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;postgres&amp;quot;
&lt;br&gt;2008-11-19 00:01:48 EET &amp;nbsp; &amp;nbsp;11729 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;mydb1&amp;quot;
&lt;br&gt;2008-11-19 00:02:48 EET &amp;nbsp; &amp;nbsp;11730 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;emydb1&amp;quot;
&lt;br&gt;2008-11-19 00:03:48 EET &amp;nbsp; &amp;nbsp;11731 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;template1&amp;quot;
&lt;br&gt;2008-11-19 00:04:48 EET &amp;nbsp; &amp;nbsp;11732 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;testmydb1&amp;quot;
&lt;br&gt;2008-11-19 00:05:48 EET &amp;nbsp; &amp;nbsp;11733 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;mydb3&amp;quot;
&lt;br&gt;2008-11-19 00:06:48 EET &amp;nbsp; &amp;nbsp;11734 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;postgres&amp;quot;
&lt;br&gt;2008-11-19 00:07:48 EET &amp;nbsp; &amp;nbsp;11735 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;mydb1&amp;quot;
&lt;br&gt;2008-11-19 00:08:48 EET &amp;nbsp; &amp;nbsp;11736 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;emydb1&amp;quot;
&lt;br&gt;2008-11-19 00:09:48 EET &amp;nbsp; &amp;nbsp;11737 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;template1&amp;quot;
&lt;br&gt;2008-11-19 00:10:48 EET &amp;nbsp; &amp;nbsp;11750 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;testmydb1&amp;quot;
&lt;br&gt;2008-11-19 00:11:48 EET &amp;nbsp; &amp;nbsp;11751 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;mydb3&amp;quot;
&lt;br&gt;2008-11-19 00:12:48 EET &amp;nbsp; &amp;nbsp;11752 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;postgres&amp;quot;
&lt;br&gt;2008-11-19 00:13:48 EET &amp;nbsp; &amp;nbsp;11753 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;mydb1&amp;quot;
&lt;br&gt;2008-11-19 00:14:48 EET &amp;nbsp; &amp;nbsp;11754 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;emydb1&amp;quot;
&lt;br&gt;2008-11-19 00:15:48 EET &amp;nbsp; &amp;nbsp;11755 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;template1&amp;quot;
&lt;br&gt;2008-11-19 00:16:48 EET &amp;nbsp; &amp;nbsp;11756 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;testmydb1&amp;quot;
&lt;br&gt;2008-11-19 00:17:48 EET &amp;nbsp; &amp;nbsp;11757 &amp;nbsp;1 LOG: &amp;nbsp;autovacuum: processing database 
&lt;br&gt;&amp;quot;mydb3&amp;quot;
&lt;br&gt;... 
&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20628713&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20628713.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20628676</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T12:07:02Z</published>
	<updated>2008-11-21T12:07:02Z</updated>
	<author>
		<name>Tom Lane-2</name>
	</author>
	<content type="html">PFC &amp;lt;&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20628676&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;lists@...&lt;/a&gt;&amp;gt; writes:
&lt;br&gt;&amp;gt; Index on orders_products( product_id ) and orders_products( order_id ):
&lt;br&gt;&amp;gt; 	=&amp;gt; Same plan
&lt;br&gt;&lt;br&gt;&amp;gt; 	Note that in this case, a smarter planner would use the new index to &amp;nbsp;
&lt;br&gt;&amp;gt; perform a BitmapAnd before hitting the heap to get the rows.
&lt;br&gt;&lt;br&gt;Considering that the query has no constraint on
&lt;br&gt;orders_products.order_id, I'm not sure what you think the extra index is
&lt;br&gt;supposed to be used *for*.
&lt;br&gt;&lt;br&gt;(Well, we could put orders as the outside of a nestloop and then we'd
&lt;br&gt;have such a constraint, but with 30000 orders rows to process that plan
&lt;br&gt;would lose big.)
&lt;br&gt;&lt;br&gt;(And yes, the planner did consider such a plan along the way.
&lt;br&gt;See choose_bitmap_and.)
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; regards, tom lane
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20628676&amp;i=1&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20628676.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20628394</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T11:48:05Z</published>
	<updated>2008-11-21T11:48:05Z</updated>
	<author>
		<name>Alvaro Herrera-7</name>
	</author>
	<content type="html">Andrus wrote:
&lt;br&gt;&lt;br&gt;&amp;gt; Will value of 30 allow other clients to work when VACUUM FULL is running ?
&lt;br&gt;&lt;br&gt;1. vacuum_cost_delay does not affect vacuum full
&lt;br&gt;2. vacuum full is always blocking, regardless of settings
&lt;br&gt;&lt;br&gt;So I gather you're not doing any vacuuming, eh?
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Alvaro Herrera &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;a href=&quot;http://www.CommandPrompt.com/&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.CommandPrompt.com/&lt;/a&gt;&lt;br&gt;The PostgreSQL Company - Command Prompt, Inc.
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20628394&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20628394.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20628359</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T11:45:11Z</published>
	<updated>2008-11-21T11:45:11Z</updated>
	<author>
		<name>Andrus Moor-2</name>
	</author>
	<content type="html">Alvaro,
&lt;br&gt;&lt;br&gt;&amp;gt; Are you really using vacuum_cost_delay=2000? &amp;nbsp;If so, therein lies your
&lt;br&gt;&amp;gt; problem. &amp;nbsp;That's a silly value to use for that variable. &amp;nbsp;Useful values
&lt;br&gt;&amp;gt; are in the 20-40 range probably, or maybe 10-100 being extremely
&lt;br&gt;&amp;gt; generous.
&lt;br&gt;&lt;br&gt;Thank you.
&lt;br&gt;My 8.1.4 postgresql.conf does not contain such option. So vacuum_cost_delay 
&lt;br&gt;is off probably.
&lt;br&gt;Since doc does not recommend any value, I planned to use 2000
&lt;br&gt;&lt;br&gt;Will value of 30 allow other clients to work when VACUUM FULL is running ?
&lt;br&gt;&lt;br&gt;Uncommented relevant values in postgresql.conf file are:
&lt;br&gt;&lt;br&gt;shared_buffers = 15000
&lt;br&gt;work_mem = 512
&lt;br&gt;maintenance_work_mem = 131072
&lt;br&gt;fsync = on
&lt;br&gt;effective_cache_size= 70000
&lt;br&gt;log_min_duration_statement= 30000
&lt;br&gt;&lt;br&gt;Andrus. 
&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20628359&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20628359.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20627939</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T11:16:46Z</published>
	<updated>2008-11-21T11:16:46Z</updated>
	<author>
		<name>Alvaro Herrera-7</name>
	</author>
	<content type="html">Andrus wrote:
&lt;br&gt;&lt;br&gt;&amp;gt; I discovered vacuum_cost_delay=2000 option. Will this remove blocking 
&lt;br&gt;&amp;gt; issue and allow vacuum full to work ?
&lt;br&gt;&lt;br&gt;No.
&lt;br&gt;&lt;br&gt;Are you really using vacuum_cost_delay=2000? &amp;nbsp;If so, therein lies your
&lt;br&gt;problem. &amp;nbsp;That's a silly value to use for that variable. &amp;nbsp;Useful values
&lt;br&gt;are in the 20-40 range probably, or maybe 10-100 being extremely
&lt;br&gt;generous.
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Alvaro Herrera &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;a href=&quot;http://www.CommandPrompt.com/&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.CommandPrompt.com/&lt;/a&gt;&lt;br&gt;PostgreSQL Replication, Consulting, Custom Development, 24x7 support
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20627939&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20627939.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20627893</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T11:13:46Z</published>
	<updated>2008-11-21T11:13:46Z</updated>
	<author>
		<name>Alan Hodgson</name>
	</author>
	<content type="html">On Friday 21 November 2008, &amp;quot;Andrus&amp;quot; &amp;lt;&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20627893&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;kobruleht2@...&lt;/a&gt;&amp;gt; wrote:
&lt;br&gt;&amp;gt; Those commands cause server probably to stop responding to other client
&lt;br&gt;&amp;gt; like vacuum full pg_shdepend
&lt;br&gt;&amp;gt; did.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Should vacuum_cost_delay = 2000 allow other users to work when running
&lt;br&gt;&amp;gt; those commands ?
&lt;br&gt;&lt;br&gt;Any vacuum full or cluster will lock out other clients. A high 
&lt;br&gt;vacuum_cost_delay will just make the vacuum run slower.
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Corporations will ingest natural resources and defecate garbage until all 
&lt;br&gt;resources are depleted, debt can no longer be repaid and our money becomes 
&lt;br&gt;worthless - Jay Hanson
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20627893&amp;i=1&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20627893.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20627836</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T11:10:21Z</published>
	<updated>2008-11-21T11:10:21Z</updated>
	<author>
		<name>Andrus Moor-2</name>
	</author>
	<content type="html">&amp;gt;&amp;gt; How to vacuum full pg_shdepend automatically so that other users can 
&lt;br&gt;&amp;gt;&amp;gt; work at same time ?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Your table is horribly bloated.
&lt;br&gt;&amp;gt; You must use VACUUM FULL + REINDEX (as superuser) on it, however 
&lt;br&gt;&amp;gt; unfortunately, it is blocking.
&lt;br&gt;&amp;gt; Therefore, you should wait for sunday night to do this, when noone will 
&lt;br&gt;&amp;gt; notice.
&lt;br&gt;&lt;br&gt;Shops are closed late night for a short time, including sunday night.
&lt;br&gt;This time may be shorter than time required to complete VACUUM command.
&lt;br&gt;&lt;br&gt;I discovered vacuum_cost_delay=2000 option. Will this remove blocking issue 
&lt;br&gt;and allow vacuum full to work ?
&lt;br&gt;&lt;br&gt;&amp;gt; Meanwhile, you can always VACUUM it (as superuser) and REINDEX it.
&lt;br&gt;&lt;br&gt;I expect that autovacuum does this automatically.
&lt;br&gt;&lt;br&gt;&amp;gt; And while you're at it, VACUUM FULL + reindex the entire database.
&lt;br&gt;&amp;gt; To avoid such annoyances in the future, you should ensure that autovacuum 
&lt;br&gt;&amp;gt; runs properly ; you should investigate this. If you use a cron'ed VACUUM 
&lt;br&gt;&amp;gt; that does not run as superuser, then it will not be able to VACUUM the 
&lt;br&gt;&amp;gt; system catalogs, and the problem will come back.
&lt;br&gt;&lt;br&gt;autovacuum is turned on in postgresql.conf file
&lt;br&gt;log file shows a lot of messages every day that database is vacuumed.
&lt;br&gt;I assume that it is running as user postgres.
&lt;br&gt;&lt;br&gt;I do'nt understand how autovacuum can avoid this: it does not perform vacuum 
&lt;br&gt;full so pg_shdepend ja my tables become
&lt;br&gt;bloated again and again.
&lt;br&gt;&lt;br&gt;Andrus. 
&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20627836&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20627836.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20627772</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T11:08:27Z</published>
	<updated>2008-11-21T11:08:27Z</updated>
	<author>
		<name>PFC-2</name>
	</author>
	<content type="html">&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; log file seems that mostly only those queries are slow:
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; SELECT ...
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;FROM dok JOIN rid USING (dokumnr)
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;JOIN ProductId USING (ProductId)
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;WHERE rid.ProductId LIKE :p1 || '%' AND dok.SaleDate&amp;gt;=:p2
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; :p1 and :p2 are parameters different for different queries.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; dok contains several years of data. :p2 is usually only few previous &amp;nbsp;
&lt;br&gt;&amp;gt; months
&lt;br&gt;&amp;gt; or last year ago.
&lt;br&gt;&amp;gt; SELECT column list contains fixed list of known columns from all tables.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; How to create index or materialized view to optimize this types of &amp;nbsp;
&lt;br&gt;&amp;gt; queries ?
&lt;br&gt;&amp;gt;
&lt;/div&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I would remove some granularity, for instance create a summary table &amp;nbsp;
&lt;br&gt;(materialized view) by month :
&lt;br&gt;&lt;br&gt;- date (contains the first day of the month)
&lt;br&gt;- product_id
&lt;br&gt;- total quantity, total price sold in given month
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; You get the idea.
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If your products belong to categories, and you make queries on all the &amp;nbsp;
&lt;br&gt;products in a category, it could be worth making a summary table for &amp;nbsp;
&lt;br&gt;categories also.
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20627772&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20627772.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20627629</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T11:00:09Z</published>
	<updated>2008-11-21T11:00:09Z</updated>
	<author>
		<name>Andrus Moor-2</name>
	</author>
	<content type="html">Thomas,
&lt;br&gt;&lt;br&gt;Thank you.
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; Just the most important points:
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; 1) &amp;quot;dok&amp;quot; table contains 1235086 row versions in 171641 pages (with 8kB
&lt;br&gt;&amp;gt; pages this means 1.4GB MB of data), but there are 1834279 unused item
&lt;br&gt;&amp;gt; pointers (i.e. about 60% of the space is wasted)
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; 2) &amp;quot;rid&amp;quot; table contains 3275189 roiws in 165282 (with 8kB pages this means
&lt;br&gt;&amp;gt; about 1.3GB of data), but there are 1878923 unused item pointers (i.e.
&lt;br&gt;&amp;gt; about 30% of the space is wasted)
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; 3) don't forget to execute analyze after vacuuming (or vacuum analyze)
&lt;/div&gt;&lt;br&gt;autovacuum is running.
&lt;br&gt;So if I understand properly, I must ran
&lt;br&gt;VACUUM FULL ANALYZE dok;
&lt;br&gt;VACUUM FULL ANALYZE rid;
&lt;br&gt;&lt;br&gt;Those commands cause server probably to stop responding to other client like
&lt;br&gt;vacuum full pg_shdepend
&lt;br&gt;did.
&lt;br&gt;&lt;br&gt;Should vacuum_cost_delay = 2000 allow other users to work when running those
&lt;br&gt;commands ?
&lt;br&gt;&lt;br&gt;&amp;gt; 4) I'm not sure why the sizes reported by you (for example 2.3GB vs 1.5GB
&lt;br&gt;&amp;gt; for &amp;quot;doc&amp;quot; table) - the difference seems too large for me.
&lt;br&gt;&lt;br&gt;I used pg_total_relation_size(). So 2.3 GB includes indexes also:
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp;8 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44286 dok_tasudok_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;245 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;10 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44283 dok_klient_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 142 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; 18 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44288 dok_tasumata_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 91 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; 19 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44289 dok_tellimus_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 89 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;20 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44284dok_krdokumnr_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;89 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44285 dok_kuupaev_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;84 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;22 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;43531 makse_pkey &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 77 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;23 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;43479 dok_pkey &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 74 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44282 dok_dokumnr_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;74 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;26 &amp;nbsp; &amp;nbsp; 18663923 dok_yksus_pattern_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;43 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;27 &amp;nbsp; &amp;nbsp; 18801591 dok_sihtyksus_pattern_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;42 MB
&lt;br&gt;&lt;br&gt;&amp;gt; Anyway the amount of wasted rows seems significant to me - I'd try to
&lt;br&gt;&amp;gt; solve this first. Either by VACUUM FULL or by CLUSTER. The CLUSTER will
&lt;br&gt;&amp;gt; lock the table exclusively, but the results may be better (when sorting by
&lt;br&gt;&amp;gt; a well chosen index). Don't forget to run ANALYZE afterwards.
&lt;br&gt;&lt;br&gt;How to invoke those commands so that other clients can continue work?
&lt;br&gt;I'm using 8.1.4.
&lt;br&gt;Log files show that autovacuum is running.
&lt;br&gt;&lt;br&gt;I'm planning the following solution:
&lt;br&gt;&lt;br&gt;1. Set
&lt;br&gt;&lt;br&gt;vacuum_cost_delay=2000
&lt;br&gt;&lt;br&gt;2. Run the following commands periodically in this order:
&lt;br&gt;&lt;br&gt;VACUUM FULL;
&lt;br&gt;vacuum full pg_shdepend;
&lt;br&gt;CLUSTER rid on (toode);
&lt;br&gt;CLUSTER dok &amp;nbsp;on (kuupaev);
&lt;br&gt;REINDEX DATABASE mydb;
&lt;br&gt;REINDEX SYSTEM mydb;
&lt;br&gt;ANALYZE;
&lt;br&gt;&lt;br&gt;Are all those command required or can something leaved out ?
&lt;br&gt;&lt;br&gt;&amp;gt; Several other things to consider:
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; 1) Regarding the toode column - why are you using CHAR(20) when the values
&lt;br&gt;&amp;gt; are actually shorter? This may significantly increase the amount of space
&lt;br&gt;&amp;gt; required.
&lt;br&gt;&lt;br&gt;There may be some products whose codes may be up to 20 characters.
&lt;br&gt;PostgreSQL does not hold trailing spaces in db, so this does *not* affect to
&lt;br&gt;space.
&lt;br&gt;&lt;br&gt;&amp;gt; 2) I've noticed the CPU used is Celeron, which may negatively affect the
&lt;br&gt;&amp;gt; speed of hash computation. I'd try to replace it by something faster - say
&lt;br&gt;&amp;gt; INTEGER as an artificial primary key of the &amp;quot;toode&amp;quot; table and using it as
&lt;br&gt;&amp;gt; a FK in other tables. &amp;nbsp;This might improve the &amp;quot;Bitmap Heap Scan on rid&amp;quot;
&lt;br&gt;&amp;gt; part, but yes - it's just a minor improvement compared to the &amp;quot;Hash Join&amp;quot;
&lt;br&gt;&amp;gt; part of the query.
&lt;br&gt;&lt;br&gt;Natural key Toode CHAR(20) is used widely in different queries. Replacing it
&lt;br&gt;with
&lt;br&gt;INT surrogate key requires major application rewrite.
&lt;br&gt;&lt;br&gt;Should I add surrogate index INT columns to toode and rid table and measure
&lt;br&gt;test query speed in this case?
&lt;br&gt;&lt;br&gt;&amp;gt; Materialized views seem like a good idea to me, but maybe I'm not seeing
&lt;br&gt;&amp;gt; something. What do you mean by &amp;quot;reports are different&amp;quot;? If there is a lot
&lt;br&gt;&amp;gt; of rows for a given product / day, then creating an aggregated table with
&lt;br&gt;&amp;gt; (product code / day) as a primary key is quite simple. It may require a
&lt;br&gt;&amp;gt; lot of disk space, but it'll remove the hash join overhead. But if the
&lt;br&gt;&amp;gt; queries are very different, then it may be difficult to build such
&lt;br&gt;&amp;gt; materialized view(s).
&lt;br&gt;&lt;br&gt;log file seems that mostly only those queries are slow:
&lt;br&gt;&lt;br&gt;SELECT ...
&lt;br&gt;&amp;nbsp; &amp;nbsp;FROM dok JOIN rid USING (dokumnr)
&lt;br&gt;&amp;nbsp; &amp;nbsp;JOIN ProductId USING (ProductId)
&lt;br&gt;&amp;nbsp; &amp;nbsp;WHERE rid.ProductId LIKE :p1 || '%' AND dok.SaleDate&amp;gt;=:p2
&lt;br&gt;&lt;br&gt;:p1 and :p2 are parameters different for different queries.
&lt;br&gt;&lt;br&gt;dok contains several years of data. :p2 is usually only few previous months
&lt;br&gt;or last year ago.
&lt;br&gt;SELECT column list contains fixed list of known columns from all tables.
&lt;br&gt;&lt;br&gt;How to create index or materialized view to optimize this types of queries ?
&lt;br&gt;&lt;br&gt;Andrus.
&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20627629&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20627629.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20627138</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T10:31:37Z</published>
	<updated>2008-11-21T10:31:37Z</updated>
	<author>
		<name>PFC-2</name>
	</author>
	<content type="html">&lt;br&gt;&amp;gt; Server has 2 GB RAM.
&lt;br&gt;&amp;gt; It has SATA RAID 0,1 integrated controller (1.5Gbps) and SAMSUNG HD160JJ
&lt;br&gt;&amp;gt; mirrored disks.
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; You could perhaps run a little check on the performance of the RAID, is &amp;nbsp;
&lt;br&gt;it better than linux software RAID ?
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Does it leverage NCQ appropriately when running queries in parallel ?
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; &amp;nbsp;-- Receipt headers:
&lt;br&gt;&amp;gt; DOK ( dokumnr &amp;nbsp;INT SERIAL PRIMARY KEY,
&lt;br&gt;&amp;gt; &amp;nbsp;kuupaev DATE --- sales date
&lt;br&gt;&amp;gt; )
&lt;br&gt;&amp;gt; &amp;nbsp;-- Receipt details
&lt;br&gt;&amp;gt; RID ( dokumnr INT,
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; toode CHAR(20), &amp;nbsp;-- item code
&lt;br&gt;&amp;gt; CONSTRAINT rid_dokumnr_fkey FOREIGN KEY (dokumnr) &amp;nbsp; REFERENCES dok
&lt;br&gt;&amp;gt; (dokumnr),
&lt;br&gt;&amp;gt; &amp;nbsp;CONSTRAINT rid_toode_fkey FOREIGN KEY (toode)
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;REFERENCES firma2.toode (toode)
&lt;br&gt;&amp;gt; )
&lt;br&gt;&amp;gt; &amp;nbsp;-- Products
&lt;br&gt;&amp;gt; TOODE (
&lt;br&gt;&amp;gt; &amp;nbsp;toode CHAR(20) PRIMARY KEY
&lt;br&gt;&amp;gt; )
&lt;/div&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; OK so pretty straightforward :
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dok &amp;lt;-(dokumnr)-&amp;gt; rid &amp;lt;-(toode)-&amp;gt; toode
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; toode.toode should really be an INT though.
&lt;br&gt;&lt;br&gt;&amp;gt;&amp;gt; explain analyze
&lt;br&gt;&amp;gt;&amp;gt; SELECT sum(1)
&lt;br&gt;&amp;gt;&amp;gt; &amp;nbsp; FROM dok JOIN rid USING (dokumnr)
&lt;br&gt;&amp;gt;&amp;gt; &amp;nbsp; JOIN toode USING (toode)
&lt;br&gt;&amp;gt;&amp;gt; &amp;nbsp; LEFT JOIN artliik using(grupp,liik)
&lt;br&gt;&amp;gt;&amp;gt; &amp;nbsp; WHERE rid.toode='X05' AND dok.kuupaev&amp;gt;='2008-09-01'
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; By the way, note that the presence of the toode table in the query above &amp;nbsp;
&lt;br&gt;is not required at all, unless you use columns of toode in your aggregates.
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Let's play with that, after all, it's friday night.
&lt;br&gt;&lt;br&gt;BEGIN;
&lt;br&gt;CREATE TABLE orders (order_id INTEGER NOT NULL, order_date DATE NOT NULL);
&lt;br&gt;CREATE TABLE products (product_id INTEGER NOT NULL, product_name TEXT NOT &amp;nbsp;
&lt;br&gt;NULL);
&lt;br&gt;CREATE TABLE orders_products (order_id INTEGER NOT NULL, product_id &amp;nbsp;
&lt;br&gt;INTEGER NOT NULL, padding1 TEXT, padding2 TEXT);
&lt;br&gt;&lt;br&gt;INSERT INTO products SELECT n, 'product number ' || n::TEXT FROM &amp;nbsp;
&lt;br&gt;generate_series(1,40000) AS n;
&lt;br&gt;INSERT INTO orders SELECT n,'2000-01-01'::date + (n/1000 * '1 &amp;nbsp;
&lt;br&gt;DAY'::interval) FROM generate_series(1,1000000) AS n;
&lt;br&gt;&lt;br&gt;SET work_mem TO '1GB';
&lt;br&gt;INSERT INTO orders_products SELECT &amp;nbsp;
&lt;br&gt;a,b,'aibaifbaurgbyioubyfazierugybfoaybofauez', &amp;nbsp;
&lt;br&gt;'hfohbdsqbhjhqsvdfiuazvfgiurvgazrhbazboifhaoifh'
&lt;br&gt;&amp;nbsp; &amp;nbsp;FROM (SELECT DISTINCT (1+(n/10))::INTEGER AS a, &amp;nbsp;
&lt;br&gt;(1+(random()*39999))::INTEGER AS b FROM generate_series( 1,9999999 ) AS n) &amp;nbsp;
&lt;br&gt;AS x;
&lt;br&gt;&lt;br&gt;DELETE FROM orders_products WHERE product_id NOT IN (SELECT product_id &amp;nbsp;
&lt;br&gt;&amp;nbsp;FROM products);
&lt;br&gt;DELETE FROM orders_products WHERE order_id NOT IN (SELECT order_id FROM &amp;nbsp;
&lt;br&gt;orders);
&lt;br&gt;ALTER TABLE orders ADD PRIMARY KEY (order_id);
&lt;br&gt;ALTER TABLE products ADD PRIMARY KEY (product_id);
&lt;br&gt;ALTER TABLE orders_products ADD PRIMARY KEY (order_id,product_id);
&lt;br&gt;ALTER TABLE orders_products ADD FOREIGN KEY (product_id) REFERENCES &amp;nbsp;
&lt;br&gt;products( product_id ) ON DELETE CASCADE;
&lt;br&gt;ALTER TABLE orders_products ADD FOREIGN KEY (order_id) REFERENCES orders( &amp;nbsp;
&lt;br&gt;order_id ) ON DELETE CASCADE;
&lt;br&gt;CREATE INDEX orders_date ON orders( order_date );
&lt;br&gt;COMMIT;
&lt;br&gt;SET work_mem TO DEFAULT;
&lt;br&gt;ANALYZE;
&lt;br&gt;&lt;br&gt;With the following query :
&lt;br&gt;&lt;br&gt;EXPLAIN ANALYZE SELECT sum(1)
&lt;br&gt;&amp;nbsp;FROM orders
&lt;br&gt;JOIN orders_products USING (order_id)
&lt;br&gt;JOIN products USING (product_id)
&lt;br&gt;WHERE orders.order_date BETWEEN '2000-01-01' AND '2000-02-01'
&lt;br&gt;AND products.product_id = 12345;
&lt;br&gt;&lt;br&gt;I get the following results :
&lt;br&gt;&lt;br&gt;orders_products has a PK index on (order_id, product_id). I dropped it.
&lt;br&gt;&lt;br&gt;No index on orders_products :
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; =&amp;gt; Big seq scan (16 seconds)
&lt;br&gt;&lt;br&gt;Index on orders_products( product_id ) :
&lt;br&gt;&amp;nbsp; Aggregate &amp;nbsp;(cost=2227.22..2227.23 rows=1 width=0) (actual &amp;nbsp;
&lt;br&gt;time=108.204..108.205 rows=1 loops=1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; -&amp;gt; &amp;nbsp;Nested Loop &amp;nbsp;(cost=1312.30..2227.20 rows=7 width=0) (actual &amp;nbsp;
&lt;br&gt;time=105.929..108.191 rows=6 loops=1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt; &amp;nbsp;Index Scan using products_pkey on products &amp;nbsp;(cost=0.00..8.27 &amp;nbsp;
&lt;br&gt;rows=1 width=4) (actual time=0.010..0.014 rows=1 loops=1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Index Cond: (product_id = 12345)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt; &amp;nbsp;Hash Join &amp;nbsp;(cost=1312.30..2218.85 rows=7 width=4) (actual &amp;nbsp;
&lt;br&gt;time=105.914..108.167 rows=6 loops=1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Hash Cond: (orders_products.order_id = orders.order_id)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt; &amp;nbsp;Bitmap Heap Scan on orders_products &amp;nbsp;(cost=6.93..910.80 &amp;nbsp;
&lt;br&gt;rows=232 width=8) (actual time=0.194..2.175 rows=246 loops=1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Recheck Cond: (product_id = 12345)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt; &amp;nbsp;Bitmap Index Scan on orders_products_product_id &amp;nbsp; 
&lt;br&gt;(cost=0.00..6.87 rows=232 width=0) (actual time=0.129..0.129 rows=246 &amp;nbsp;
&lt;br&gt;loops=1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Index Cond: (product_id = 12345)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt; &amp;nbsp;Hash &amp;nbsp;(cost=949.98..949.98 rows=28432 width=4) (actual &amp;nbsp;
&lt;br&gt;time=105.696..105.696 rows=31999 loops=1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt; &amp;nbsp;Index Scan using orders_date on orders &amp;nbsp; 
&lt;br&gt;(cost=0.00..949.98 rows=28432 width=4) (actual time=0.059..64.443 &amp;nbsp;
&lt;br&gt;rows=31999 loops=1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Index Cond: ((order_date &amp;gt;= '2000-01-01'::date) &amp;nbsp;
&lt;br&gt;AND (order_date &amp;lt;= '2000-02-01'::date))
&lt;br&gt;&amp;nbsp; Total runtime: 108.357 ms
&lt;br&gt;(don't trust this timing, it's a bit cached, this is the same plan as you &amp;nbsp;
&lt;br&gt;get)
&lt;br&gt;&lt;br&gt;Index on orders_products( product_id ) and orders_products( order_id ):
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; =&amp;gt; Same plan
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Note that in this case, a smarter planner would use the new index to &amp;nbsp;
&lt;br&gt;perform a BitmapAnd before hitting the heap to get the rows.
&lt;br&gt;&lt;br&gt;Index on ( order_id, product_id ), orders_products( product_id ):
&lt;br&gt;Index on ( order_id, product_id ):
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; =&amp;gt; Different plan, slower (especially in second case).
&lt;br&gt;&lt;br&gt;If a &amp;quot;order_date&amp;quot; column is added to the &amp;quot;orders_products&amp;quot; table to make &amp;nbsp;
&lt;br&gt;it into some kind of materialized view :
&lt;br&gt;&lt;br&gt;CREATE TABLE orders_products2 AS SELECT orders.order_id, &amp;nbsp;
&lt;br&gt;orders.order_date, product_id FROM orders JOIN orders_products USING &amp;nbsp;
&lt;br&gt;(order_id);
&lt;br&gt;&lt;br&gt;And an index is created on (product_id, order_date) we get this :
&lt;br&gt;&lt;br&gt;&amp;nbsp; Aggregate &amp;nbsp;(cost=100.44..100.45 rows=1 width=0) (actual time=0.176..0.177 &amp;nbsp;
&lt;br&gt;rows=1 loops=1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; -&amp;gt; &amp;nbsp;Nested Loop &amp;nbsp;(cost=0.00..100.42 rows=7 width=0) (actual &amp;nbsp;
&lt;br&gt;time=0.083..0.168 rows=6 loops=1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt; &amp;nbsp;Index Scan using products_pkey on products &amp;nbsp;(cost=0.00..8.27 &amp;nbsp;
&lt;br&gt;rows=1 width=4) (actual time=0.012..0.013 rows=1 loops=1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Index Cond: (product_id = 12345)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt; &amp;nbsp;Nested Loop &amp;nbsp;(cost=0.00..92.08 rows=7 width=4) (actual &amp;nbsp;
&lt;br&gt;time=0.068..0.147 rows=6 loops=1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt; &amp;nbsp;Index Scan using orders_products2_pid_date on &amp;nbsp;
&lt;br&gt;orders_products2 &amp;nbsp;(cost=0.00..33.50 rows=7 width=8) (actual &amp;nbsp;
&lt;br&gt;time=0.053..0.076 rows=6 loops=1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Index Cond: ((product_id = 12345) AND (order_date &amp;gt;= &amp;nbsp;
&lt;br&gt;'2000-01-01'::date) AND (order_date &amp;lt;= '2000-02-01'::date))
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt; &amp;nbsp;Index Scan using orders_pkey on orders &amp;nbsp; 
&lt;br&gt;(cost=0.00..8.36 rows=1 width=4) (actual time=0.008..0.009 rows=1 loops=6)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Index Cond: (orders.order_id = &amp;nbsp;
&lt;br&gt;orders_products2.order_id)
&lt;br&gt;&amp;nbsp; Total runtime: 0.246 ms
&lt;br&gt;&lt;br&gt;An index on (order_date,product_id) produces the same effect ; the index &amp;nbsp;
&lt;br&gt;scan is slower, but the heap scan uses the same amount of IO.
&lt;br&gt;&lt;br&gt;Two indexes, (order_date) and (product_id), strangely, do not produce a &amp;nbsp;
&lt;br&gt;BitmapAnd ; instead a plan with more IO is chosen.
&lt;br&gt;&lt;br&gt;&lt;br&gt;&amp;gt;&amp;gt; - denormalization (ie adding a column in one of your tables and a
&lt;br&gt;&amp;gt;&amp;gt; multicolumn index)
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; For this query it is possible to duplicate kuupaev column to rid table.
&lt;br&gt;&amp;gt; However most of the this seems to go to scanning rid table, so I suspect
&lt;br&gt;&amp;gt; that this will help.
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Yes, most of the time goes to scanning rid table, and this is the time &amp;nbsp;
&lt;br&gt;that should be reduced.
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Adding a date column in &amp;quot;rid&amp;quot; would allow you to create a multicolumn &amp;nbsp;
&lt;br&gt;index on rid (dokumnr,date) which would massively speed up the particular &amp;nbsp;
&lt;br&gt;query above.
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If you don't create a multicolumn index, this denormalization is useless.
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Basically instead of scanning all rows in &amp;quot;rid&amp;quot; where
&lt;br&gt;&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; - materialized views
&lt;br&gt;&amp;gt;&amp;gt; - materialized summary tables (ie. summary of sales for last month, for
&lt;br&gt;&amp;gt;&amp;gt; instance)
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; There are about 1000 items and reports are different.
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; It all depends on what you put in your summary table...
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20627138&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20627138.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20626565</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T09:57:37Z</published>
	<updated>2008-11-21T09:57:37Z</updated>
	<author>
		<name>PFC-2</name>
	</author>
	<content type="html">&lt;br&gt;&amp;gt; How to vacuum full pg_shdepend automatically so that other users can &amp;nbsp;
&lt;br&gt;&amp;gt; work at same time ?
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Your table is horribly bloated.
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; You must use VACUUM FULL + REINDEX (as superuser) on it, however &amp;nbsp;
&lt;br&gt;unfortunately, it is blocking.
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Therefore, you should wait for sunday night to do this, when noone will &amp;nbsp;
&lt;br&gt;notice.
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Meanwhile, you can always VACUUM it (as superuser) and REINDEX it.
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; And while you're at it, VACUUM FULL + reindex the entire database.
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; To avoid such annoyances in the future, you should ensure that autovacuum &amp;nbsp;
&lt;br&gt;runs properly ; you should investigate this. If you use a cron'ed VACUUM &amp;nbsp;
&lt;br&gt;that does not run as superuser, then it will not be able to VACUUM the &amp;nbsp;
&lt;br&gt;system catalogs, and the problem will come back.
&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20626565&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20626565.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20626446</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T09:51:01Z</published>
	<updated>2008-11-21T09:51:01Z</updated>
	<author>
		<name>Andrus Moor-2</name>
	</author>
	<content type="html">Richard,
&lt;br&gt;&lt;br&gt;Thank you.
&lt;br&gt;&lt;br&gt;&amp;gt; Try &amp;quot;SELECT count(*) FROM pg_shdepend&amp;quot;.
&lt;br&gt;&lt;br&gt;This query returns 3625 &amp;nbsp;and takes 35 seconds to run.
&lt;br&gt;&lt;br&gt;&amp;gt; If it's not a million rows, then the table is bloated. Try (as postgres
&lt;br&gt;&amp;gt; or some other db superuser) &amp;quot;vacuum full pg_shdepend&amp;quot; and a &amp;quot;reindex
&lt;br&gt;&amp;gt; pg_shdepend&amp;quot;.
&lt;br&gt;&lt;br&gt;vacuum full verbose pg_shdepend
&lt;br&gt;INFO: &amp;nbsp;vacuuming &amp;quot;pg_catalog.pg_shdepend&amp;quot;
&lt;br&gt;INFO: &amp;nbsp;&amp;quot;pg_shdepend&amp;quot;: found 16103561 removable, 3629 nonremovable row 
&lt;br&gt;versions in 131425 pages
&lt;br&gt;DETAIL: &amp;nbsp;0 dead row versions cannot be removed yet.
&lt;br&gt;Nonremovable row versions range from 49 to 49 bytes long.
&lt;br&gt;There were 0 unused item pointers.
&lt;br&gt;Total free space (including removable row versions) is 1009387632 bytes.
&lt;br&gt;131363 pages are or will become empty, including 0 at the end of the table.
&lt;br&gt;131425 pages containing 1009387632 free bytes are potential move 
&lt;br&gt;destinations.
&lt;br&gt;CPU 2.12s/1.69u sec elapsed 52.66 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;pg_shdepend_depender_index&amp;quot; now contains 3629 row versions in 
&lt;br&gt;101794 pages
&lt;br&gt;DETAIL: &amp;nbsp;16103561 index row versions were removed.
&lt;br&gt;101311 index pages have been deleted, 20000 are currently reusable.
&lt;br&gt;CPU 20.12s/14.52u sec elapsed 220.66 sec.
&lt;br&gt;&lt;br&gt;After 400 seconds of run I got phone calls that server does not respond to 
&lt;br&gt;other clients. So I was forced to cancel &amp;quot;vacuum full verbose pg_shdepend
&lt;br&gt;&amp;quot; command.
&lt;br&gt;&lt;br&gt;How to run it so that other users can use database at same time ?
&lt;br&gt;&lt;br&gt;&amp;gt; If it is a million rows, you'll need to find out why. Do you have a lot
&lt;br&gt;&amp;gt; of temporary tables that aren't being dropped or something similar?
&lt;br&gt;&lt;br&gt;Application creates temporary tables in many places. Every sales operation 
&lt;br&gt;probably creates some temporary tables.
&lt;br&gt;Should I change something in configuration or change application (Only 
&lt;br&gt;single POS application which is used to access this db) or is only solution 
&lt;br&gt;to manully run
&lt;br&gt;&lt;br&gt;vacuum full pg_shdepend
&lt;br&gt;reindex pg_shdepend
&lt;br&gt;&lt;br&gt;periodically ?
&lt;br&gt;How to vacuum full pg_shdepend automatically so that other users can work at 
&lt;br&gt;same time ?
&lt;br&gt;&lt;br&gt;Hopefully this table size does not affect to query speed.
&lt;br&gt;&lt;br&gt;Andrus. 
&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20626446&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20626446.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20624722</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T08:32:50Z</published>
	<updated>2008-11-21T08:32:50Z</updated>
	<author>
		<name>Richard Huxton</name>
	</author>
	<content type="html">Andrus wrote:
&lt;br&gt;&amp;gt;&amp;gt; - what's the size of the dataset relative to the RAM ?
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; Db size is 7417 MB
&lt;br&gt;&amp;gt; relevant table sizes in desc by size order:
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;40595 dok &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2345 MB
&lt;br&gt;&lt;br&gt;&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1214 pg_shdepend &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2259 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1232 pg_shdepend_depender_index &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;795 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1233 pg_shdepend_reference_index &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 438 MB
&lt;br&gt;&lt;br&gt;These three are highly suspicious. They track dependencies between
&lt;br&gt;system object (so you can't drop function F because trigger T depends on
&lt;br&gt;it).
&lt;br&gt;&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/docs/8.3/static/catalog-pg-shdepend.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/docs/8.3/static/catalog-pg-shdepend.html&lt;/a&gt;&lt;br&gt;&lt;br&gt;You've got 3.5GB of data there, which is a *lot* of dependencies.
&lt;br&gt;&lt;br&gt;Try &amp;quot;SELECT count(*) FROM pg_shdepend&amp;quot;.
&lt;br&gt;&lt;br&gt;If it's not a million rows, then the table is bloated. Try (as postgres
&lt;br&gt;or some other db superuser) &amp;quot;vacuum full pg_shdepend&amp;quot; and a &amp;quot;reindex
&lt;br&gt;pg_shdepend&amp;quot;.
&lt;br&gt;&lt;br&gt;If it is a million rows, you'll need to find out why. Do you have a lot
&lt;br&gt;of temporary tables that aren't being dropped or something similar?
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;&amp;nbsp; Richard Huxton
&lt;br&gt;&amp;nbsp; Archonet Ltd
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20624722&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20624722.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20624352</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T08:15:10Z</published>
	<updated>2008-11-21T08:15:10Z</updated>
	<author>
		<name>tv-8</name>
	</author>
	<content type="html">Just the most important points:
&lt;br&gt;&lt;br&gt;1) &amp;quot;dok&amp;quot; table contains 1235086 row versions in 171641 pages (with 8kB
&lt;br&gt;pages this means 1.4GB MB of data), but there are 1834279 unused item
&lt;br&gt;pointers (i.e. about 60% of the space is wasted)
&lt;br&gt;&lt;br&gt;2) &amp;quot;rid&amp;quot; table contains 3275189 roiws in 165282 (with 8kB pages this means
&lt;br&gt;about 1.3GB of data), but there are 1878923 unused item pointers (i.e.
&lt;br&gt;about 30% of the space is wasted)
&lt;br&gt;&lt;br&gt;3) don't forget to execute analyze after vacuuming (or vacuum analyze)
&lt;br&gt;&lt;br&gt;4) I'm not sure why the sizes reported by you (for example 2.3GB vs 1.5GB
&lt;br&gt;for &amp;quot;doc&amp;quot; table) - the difference seems too large for me.
&lt;br&gt;&lt;br&gt;Anyway the amount of wasted rows seems significant to me - I'd try to
&lt;br&gt;solve this first. Either by VACUUM FULL or by CLUSTER. The CLUSTER will
&lt;br&gt;lock the table exclusively, but the results may be better (when sorting by
&lt;br&gt;a well chosen index). Don't forget to run ANALYZE afterwards.
&lt;br&gt;&lt;br&gt;Several other things to consider:
&lt;br&gt;&lt;br&gt;1) Regarding the toode column - why are you using CHAR(20) when the values
&lt;br&gt;are actually shorter? This may significantly increase the amount of space
&lt;br&gt;required.
&lt;br&gt;&lt;br&gt;2) I've noticed the CPU used is Celeron, which may negatively affect the
&lt;br&gt;speed of hash computation. I'd try to replace it by something faster - say
&lt;br&gt;INTEGER as an artificial primary key of the &amp;quot;toode&amp;quot; table and using it as
&lt;br&gt;a FK in other tables. &amp;nbsp;This might improve the &amp;quot;Bitmap Heap Scan on rid&amp;quot;
&lt;br&gt;part, but yes - it's just a minor improvement compared to the &amp;quot;Hash Join&amp;quot;
&lt;br&gt;part of the query.
&lt;br&gt;&lt;br&gt;Materialized views seem like a good idea to me, but maybe I'm not seeing
&lt;br&gt;something. What do you mean by &amp;quot;reports are different&amp;quot;? If there is a lot
&lt;br&gt;of rows for a given product / day, then creating an aggregated table with
&lt;br&gt;(product code / day) as a primary key is quite simple. It may require a
&lt;br&gt;lot of disk space, but it'll remove the hash join overhead. But if the
&lt;br&gt;queries are very different, then it may be difficult to build such
&lt;br&gt;materialized view(s).
&lt;br&gt;&lt;br&gt;regards
&lt;br&gt;Tomas
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; PFC,
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; thank you.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; OK so vmstat says you are IO-bound, this seems logical if the same plan
&lt;br&gt;&amp;gt;&amp;gt; has widely varying timings...
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; Let's look at the usual suspects :
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; - how many dead rows in your tables ? are your tables data, or bloat ?
&lt;br&gt;&amp;gt;&amp;gt; (check vacuum verbose, etc)
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; set search_path to firma2,public;
&lt;br&gt;&amp;gt; vacuum verbose dok; vacuum verbose rid
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;vacuuming &amp;quot;firma2.dok&amp;quot;
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;dok_pkey&amp;quot; now contains 1235086 row versions in 9454 pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;100 index row versions were removed.
&lt;br&gt;&amp;gt; 0 index pages have been deleted, 0 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.16s/0.38u sec elapsed 0.77 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;dok_dokumnr_idx&amp;quot; now contains 1235086 row versions in 9454
&lt;br&gt;&amp;gt; pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;100 index row versions were removed.
&lt;br&gt;&amp;gt; 0 index pages have been deleted, 0 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.14s/0.40u sec elapsed 0.78 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;dok_klient_idx&amp;quot; now contains 1235086 row versions in 18147
&lt;br&gt;&amp;gt; pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;887 index row versions were removed.
&lt;br&gt;&amp;gt; 3265 index pages have been deleted, 3033 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.36s/0.46u sec elapsed 31.87 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;dok_krdokumnr_idx&amp;quot; now contains 1235086 row versions in
&lt;br&gt;&amp;gt; 11387
&lt;br&gt;&amp;gt; pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;&amp;gt; 1716 index pages have been deleted, 1582 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.47s/0.55u sec elapsed 63.38 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;dok_kuupaev_idx&amp;quot; now contains 1235101 row versions in 10766
&lt;br&gt;&amp;gt; pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;&amp;gt; 659 index pages have been deleted, 625 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.62s/0.53u sec elapsed 40.20 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;dok_tasudok_idx&amp;quot; now contains 1235104 row versions in 31348
&lt;br&gt;&amp;gt; pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;&amp;gt; 0 index pages have been deleted, 0 are currently reusable.
&lt;br&gt;&amp;gt; CPU 1.18s/1.08u sec elapsed 118.97 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;dok_tasudok_unique_idx&amp;quot; now contains 99 row versions in 97
&lt;br&gt;&amp;gt; pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;98 index row versions were removed.
&lt;br&gt;&amp;gt; 80 index pages have been deleted, 80 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.00s/0.00u sec elapsed 0.48 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;dok_tasumata_idx&amp;quot; now contains 1235116 row versions in 11663
&lt;br&gt;&amp;gt; pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;&amp;gt; 5340 index pages have been deleted, 5131 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.43s/0.56u sec elapsed 53.96 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;dok_tellimus_idx&amp;quot; now contains 1235122 row versions in 11442
&lt;br&gt;&amp;gt; pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;&amp;gt; 1704 index pages have been deleted, 1569 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.45s/0.59u sec elapsed 76.91 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;dok_yksus_pattern_idx&amp;quot; now contains 1235143 row versions in
&lt;br&gt;&amp;gt; 5549 pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;&amp;gt; 529 index pages have been deleted, 129 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.19s/0.46u sec elapsed 2.72 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;dok_doktyyp&amp;quot; now contains 1235143 row versions in 3899 pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;&amp;gt; 188 index pages have been deleted, 13 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.14s/0.44u sec elapsed 1.40 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;dok_sihtyksus_pattern_idx&amp;quot; now contains 1235143 row versions
&lt;br&gt;&amp;gt; in 5353 pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;&amp;gt; 286 index pages have been deleted, 5 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.13s/0.45u sec elapsed 3.01 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;&amp;quot;dok&amp;quot;: removed 119436 row versions in 13707 pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;CPU 0.80s/0.37u sec elapsed 14.15 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;&amp;quot;dok&amp;quot;: found 119436 removable, 1235085 nonremovable row versions in
&lt;br&gt;&amp;gt; 171641 pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;2 dead row versions cannot be removed yet.
&lt;br&gt;&amp;gt; There were 1834279 unused item pointers.
&lt;br&gt;&amp;gt; 0 pages are entirely empty.
&lt;br&gt;&amp;gt; CPU 6.56s/6.88u sec elapsed 450.54 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;vacuuming &amp;quot;pg_toast.pg_toast_40595&amp;quot;
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;pg_toast_40595_index&amp;quot; now contains 0 row versions in 1 pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;0 index pages have been deleted, 0 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.00s/0.00u sec elapsed 0.00 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;&amp;quot;pg_toast_40595&amp;quot;: found 0 removable, 0 nonremovable row versions in
&lt;br&gt;&amp;gt; 0
&lt;br&gt;&amp;gt; pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;0 dead row versions cannot be removed yet.
&lt;br&gt;&amp;gt; There were 0 unused item pointers.
&lt;br&gt;&amp;gt; 0 pages are entirely empty.
&lt;br&gt;&amp;gt; CPU 0.00s/0.00u sec elapsed 0.00 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;vacuuming &amp;quot;firma2.rid&amp;quot;
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;rid_pkey&amp;quot; now contains 3275197 row versions in 13959 pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;38331 index row versions were removed.
&lt;br&gt;&amp;gt; 262 index pages have been deleted, 262 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.42s/1.05u sec elapsed 58.56 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;rid_dokumnr_idx&amp;quot; now contains 3275200 row versions in 14125
&lt;br&gt;&amp;gt; pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;38331 index row versions were removed.
&lt;br&gt;&amp;gt; 572 index pages have been deleted, 571 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.49s/1.14u sec elapsed 71.57 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;rid_inpdokumnr_idx&amp;quot; now contains 3275200 row versions in
&lt;br&gt;&amp;gt; 15103
&lt;br&gt;&amp;gt; pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;38331 index row versions were removed.
&lt;br&gt;&amp;gt; 579 index pages have been deleted, 579 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.66s/1.03u sec elapsed 68.38 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;rid_toode_idx&amp;quot; now contains 3275224 row versions in 31094
&lt;br&gt;&amp;gt; pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;38331 index row versions were removed.
&lt;br&gt;&amp;gt; 2290 index pages have been deleted, 2290 are currently reusable.
&lt;br&gt;&amp;gt; CPU 1.39s/1.58u sec elapsed 333.82 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;rid_rtellimus_idx&amp;quot; now contains 3275230 row versions in 7390
&lt;br&gt;&amp;gt; pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;18591 index row versions were removed.
&lt;br&gt;&amp;gt; 0 index pages have been deleted, 0 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.18s/0.66u sec elapsed 1.78 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;index &amp;quot;rid_toode_pattern_idx&amp;quot; now contains 3275230 row versions in
&lt;br&gt;&amp;gt; 16310 pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;17800 index row versions were removed.
&lt;br&gt;&amp;gt; 0 index pages have been deleted, 0 are currently reusable.
&lt;br&gt;&amp;gt; CPU 0.44s/1.04u sec elapsed 6.55 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;&amp;quot;rid&amp;quot;: removed 38331 row versions in 3090 pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;CPU 0.20s/0.10u sec elapsed 5.49 sec.
&lt;br&gt;&amp;gt; INFO: &amp;nbsp;&amp;quot;rid&amp;quot;: found 38331 removable, 3275189 nonremovable row versions in
&lt;br&gt;&amp;gt; 165282 pages
&lt;br&gt;&amp;gt; DETAIL: &amp;nbsp;0 dead row versions cannot be removed yet.
&lt;br&gt;&amp;gt; There were 1878923 unused item pointers.
&lt;br&gt;&amp;gt; 0 pages are entirely empty.
&lt;br&gt;&amp;gt; CPU 5.06s/7.27u sec elapsed 607.59 sec.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Query returned successfully with no result in 1058319 ms.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; - what's the size of the dataset relative to the RAM ?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Db size is 7417 MB
&lt;br&gt;&amp;gt; relevant table sizes in desc by size order:
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;40595 dok &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2345 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1214 pg_shdepend &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2259 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;40926 rid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2057 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1232 pg_shdepend_depender_index &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;795 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1233 pg_shdepend_reference_index &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 438 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44286 dok_tasudok_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 245 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44299 rid_toode_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 243 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;10 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44283 dok_klient_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;142 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;11 &amp;nbsp; &amp;nbsp; 19103791 rid_toode_pattern_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 127 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44298 rid_inpdokumnr_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;118 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44297 rid_dokumnr_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 110 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;43573 rid_pkey &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;109 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;18 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44288 dok_tasumata_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;91 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;19 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44289 dok_tellimus_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;89 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;20 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44284 dok_krdokumnr_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 89 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44285 dok_kuupaev_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 84 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;23 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;43479 dok_pkey &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;74 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44282 dok_dokumnr_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 74 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;25 &amp;nbsp; &amp;nbsp; 19076304 rid_rtellimus_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 58 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;26 &amp;nbsp; &amp;nbsp; 18663923 dok_yksus_pattern_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 43 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;27 &amp;nbsp; &amp;nbsp; 18801591 dok_sihtyksus_pattern_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 42 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;29 &amp;nbsp; &amp;nbsp; 18774881 dok_doktyyp &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30 MB
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;46 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;40967 toode &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13 MB
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; server is HP Proliant DL320 G3
&lt;br&gt;&amp;gt; &lt;a href=&quot;http://h18000.www1.hp.com/products/quickspecs/12169_ca/12169_ca.HTML&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://h18000.www1.hp.com/products/quickspecs/12169_ca/12169_ca.HTML&lt;/a&gt;&lt;br&gt;&amp;gt; CPU is 2.93Ghz Celeron 256kb cache.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Server has 2 GB RAM.
&lt;br&gt;&amp;gt; It has SATA RAID 0,1 integrated controller (1.5Gbps) and SAMSUNG HD160JJ
&lt;br&gt;&amp;gt; mirrored disks.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; Now let's look more closely at the query :
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; explain analyze
&lt;br&gt;&amp;gt;&amp;gt; SELECT sum(1)
&lt;br&gt;&amp;gt;&amp;gt; &amp;nbsp; FROM dok JOIN rid USING (dokumnr)
&lt;br&gt;&amp;gt;&amp;gt; &amp;nbsp; JOIN toode USING (toode)
&lt;br&gt;&amp;gt;&amp;gt; &amp;nbsp; LEFT JOIN artliik using(grupp,liik)
&lt;br&gt;&amp;gt;&amp;gt; &amp;nbsp; WHERE rid.toode='X05' AND dok.kuupaev&amp;gt;='2008-09-01'
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; I presume doing the query without artliik changes nothing to the
&lt;br&gt;&amp;gt;&amp;gt; runtime,
&lt;br&gt;&amp;gt;&amp;gt; yes ?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Yes. After removing artkliik from join I got response times 65 and 50
&lt;br&gt;&amp;gt; seconds, so this does not make difference.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; Your problem here is that, no matter what, postgres will have to examine
&lt;br&gt;&amp;gt;&amp;gt; - all rows where dok.kuupaev&amp;gt;='2008-09-01',
&lt;br&gt;&amp;gt;&amp;gt; - and all rows where rid.toode = 'X05'.
&lt;br&gt;&amp;gt;&amp;gt; If you use dok.kuupaev&amp;gt;='2007-09-01' (note : 2007) it will probably have
&lt;br&gt;&amp;gt;&amp;gt; to scan many, many more rows.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Probably yes, since then it reads one year more sales data.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; If you perform this query often you could CLUSTER rid on (toode) and dok
&lt;br&gt;&amp;gt;&amp;gt; on (kuupaev), but this can screw other queries.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Some reports are by sales date (dok.kuupaev) and customers.
&lt;br&gt;&amp;gt; CLUSTER rid on (toode) slows them down. Also autovacuum cannot do
&lt;br&gt;&amp;gt; clustering.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; What is the meaning of the columns ?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; This is typical sales data:
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; -- Receipt headers:
&lt;br&gt;&amp;gt; DOK ( dokumnr &amp;nbsp;INT SERIAL PRIMARY KEY,
&lt;br&gt;&amp;gt; &amp;nbsp; kuupaev DATE --- sales date
&lt;br&gt;&amp;gt; )
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; -- Receipt details
&lt;br&gt;&amp;gt; RID ( dokumnr INT,
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;toode CHAR(20), &amp;nbsp;-- item code
&lt;br&gt;&amp;gt; &amp;nbsp;CONSTRAINT rid_dokumnr_fkey FOREIGN KEY (dokumnr) &amp;nbsp; REFERENCES dok
&lt;br&gt;&amp;gt; (dokumnr),
&lt;br&gt;&amp;gt; &amp;nbsp; CONSTRAINT rid_toode_fkey FOREIGN KEY (toode)
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; REFERENCES firma2.toode (toode)
&lt;br&gt;&amp;gt; )
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; -- Products
&lt;br&gt;&amp;gt; TOODE (
&lt;br&gt;&amp;gt; &amp;nbsp; toode CHAR(20) PRIMARY KEY
&lt;br&gt;&amp;gt; )
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; To make this type of query faster I would tend to think about :
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; - denormalization (ie adding a column in one of your tables and a
&lt;br&gt;&amp;gt;&amp;gt; multicolumn index)
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; For this query it is possible to duplicate kuupaev column to rid table.
&lt;br&gt;&amp;gt; However most of the this seems to go to scanning rid table, so I suspect
&lt;br&gt;&amp;gt; that this will help.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; - materialized views
&lt;br&gt;&amp;gt;&amp;gt; - materialized summary tables (ie. summary of sales for last month, for
&lt;br&gt;&amp;gt;&amp;gt; instance)
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; There are about 1000 items and reports are different.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Andrus.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; --
&lt;br&gt;&amp;gt; Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20624352&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;&amp;gt; To make changes to your subscription:
&lt;br&gt;&amp;gt; &lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;&amp;gt;
&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20624352&amp;i=1&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20624352.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20623163</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T07:12:27Z</published>
	<updated>2008-11-21T07:12:27Z</updated>
	<author>
		<name>Andrus Moor-2</name>
	</author>
	<content type="html">PFC,
&lt;br&gt;&lt;br&gt;thank you.
&lt;br&gt;&lt;br&gt;&amp;gt; OK so vmstat says you are IO-bound, this seems logical if the same plan
&lt;br&gt;&amp;gt; has widely varying timings...
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Let's look at the usual suspects :
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; - how many dead rows in your tables ? are your tables data, or bloat ?
&lt;br&gt;&amp;gt; (check vacuum verbose, etc)
&lt;br&gt;&lt;br&gt;set search_path to firma2,public;
&lt;br&gt;vacuum verbose dok; vacuum verbose rid
&lt;br&gt;&lt;br&gt;INFO: &amp;nbsp;vacuuming &amp;quot;firma2.dok&amp;quot;
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;dok_pkey&amp;quot; now contains 1235086 row versions in 9454 pages
&lt;br&gt;DETAIL: &amp;nbsp;100 index row versions were removed.
&lt;br&gt;0 index pages have been deleted, 0 are currently reusable.
&lt;br&gt;CPU 0.16s/0.38u sec elapsed 0.77 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;dok_dokumnr_idx&amp;quot; now contains 1235086 row versions in 9454 
&lt;br&gt;pages
&lt;br&gt;DETAIL: &amp;nbsp;100 index row versions were removed.
&lt;br&gt;0 index pages have been deleted, 0 are currently reusable.
&lt;br&gt;CPU 0.14s/0.40u sec elapsed 0.78 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;dok_klient_idx&amp;quot; now contains 1235086 row versions in 18147 
&lt;br&gt;pages
&lt;br&gt;DETAIL: &amp;nbsp;887 index row versions were removed.
&lt;br&gt;3265 index pages have been deleted, 3033 are currently reusable.
&lt;br&gt;CPU 0.36s/0.46u sec elapsed 31.87 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;dok_krdokumnr_idx&amp;quot; now contains 1235086 row versions in 11387 
&lt;br&gt;pages
&lt;br&gt;DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;1716 index pages have been deleted, 1582 are currently reusable.
&lt;br&gt;CPU 0.47s/0.55u sec elapsed 63.38 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;dok_kuupaev_idx&amp;quot; now contains 1235101 row versions in 10766 
&lt;br&gt;pages
&lt;br&gt;DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;659 index pages have been deleted, 625 are currently reusable.
&lt;br&gt;CPU 0.62s/0.53u sec elapsed 40.20 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;dok_tasudok_idx&amp;quot; now contains 1235104 row versions in 31348 
&lt;br&gt;pages
&lt;br&gt;DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;0 index pages have been deleted, 0 are currently reusable.
&lt;br&gt;CPU 1.18s/1.08u sec elapsed 118.97 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;dok_tasudok_unique_idx&amp;quot; now contains 99 row versions in 97 
&lt;br&gt;pages
&lt;br&gt;DETAIL: &amp;nbsp;98 index row versions were removed.
&lt;br&gt;80 index pages have been deleted, 80 are currently reusable.
&lt;br&gt;CPU 0.00s/0.00u sec elapsed 0.48 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;dok_tasumata_idx&amp;quot; now contains 1235116 row versions in 11663 
&lt;br&gt;pages
&lt;br&gt;DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;5340 index pages have been deleted, 5131 are currently reusable.
&lt;br&gt;CPU 0.43s/0.56u sec elapsed 53.96 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;dok_tellimus_idx&amp;quot; now contains 1235122 row versions in 11442 
&lt;br&gt;pages
&lt;br&gt;DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;1704 index pages have been deleted, 1569 are currently reusable.
&lt;br&gt;CPU 0.45s/0.59u sec elapsed 76.91 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;dok_yksus_pattern_idx&amp;quot; now contains 1235143 row versions in 
&lt;br&gt;5549 pages
&lt;br&gt;DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;529 index pages have been deleted, 129 are currently reusable.
&lt;br&gt;CPU 0.19s/0.46u sec elapsed 2.72 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;dok_doktyyp&amp;quot; now contains 1235143 row versions in 3899 pages
&lt;br&gt;DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;188 index pages have been deleted, 13 are currently reusable.
&lt;br&gt;CPU 0.14s/0.44u sec elapsed 1.40 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;dok_sihtyksus_pattern_idx&amp;quot; now contains 1235143 row versions 
&lt;br&gt;in 5353 pages
&lt;br&gt;DETAIL: &amp;nbsp;119436 index row versions were removed.
&lt;br&gt;286 index pages have been deleted, 5 are currently reusable.
&lt;br&gt;CPU 0.13s/0.45u sec elapsed 3.01 sec.
&lt;br&gt;INFO: &amp;nbsp;&amp;quot;dok&amp;quot;: removed 119436 row versions in 13707 pages
&lt;br&gt;DETAIL: &amp;nbsp;CPU 0.80s/0.37u sec elapsed 14.15 sec.
&lt;br&gt;INFO: &amp;nbsp;&amp;quot;dok&amp;quot;: found 119436 removable, 1235085 nonremovable row versions in 
&lt;br&gt;171641 pages
&lt;br&gt;DETAIL: &amp;nbsp;2 dead row versions cannot be removed yet.
&lt;br&gt;There were 1834279 unused item pointers.
&lt;br&gt;0 pages are entirely empty.
&lt;br&gt;CPU 6.56s/6.88u sec elapsed 450.54 sec.
&lt;br&gt;INFO: &amp;nbsp;vacuuming &amp;quot;pg_toast.pg_toast_40595&amp;quot;
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;pg_toast_40595_index&amp;quot; now contains 0 row versions in 1 pages
&lt;br&gt;DETAIL: &amp;nbsp;0 index pages have been deleted, 0 are currently reusable.
&lt;br&gt;CPU 0.00s/0.00u sec elapsed 0.00 sec.
&lt;br&gt;INFO: &amp;nbsp;&amp;quot;pg_toast_40595&amp;quot;: found 0 removable, 0 nonremovable row versions in 0 
&lt;br&gt;pages
&lt;br&gt;DETAIL: &amp;nbsp;0 dead row versions cannot be removed yet.
&lt;br&gt;There were 0 unused item pointers.
&lt;br&gt;0 pages are entirely empty.
&lt;br&gt;CPU 0.00s/0.00u sec elapsed 0.00 sec.
&lt;br&gt;INFO: &amp;nbsp;vacuuming &amp;quot;firma2.rid&amp;quot;
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;rid_pkey&amp;quot; now contains 3275197 row versions in 13959 pages
&lt;br&gt;DETAIL: &amp;nbsp;38331 index row versions were removed.
&lt;br&gt;262 index pages have been deleted, 262 are currently reusable.
&lt;br&gt;CPU 0.42s/1.05u sec elapsed 58.56 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;rid_dokumnr_idx&amp;quot; now contains 3275200 row versions in 14125 
&lt;br&gt;pages
&lt;br&gt;DETAIL: &amp;nbsp;38331 index row versions were removed.
&lt;br&gt;572 index pages have been deleted, 571 are currently reusable.
&lt;br&gt;CPU 0.49s/1.14u sec elapsed 71.57 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;rid_inpdokumnr_idx&amp;quot; now contains 3275200 row versions in 15103 
&lt;br&gt;pages
&lt;br&gt;DETAIL: &amp;nbsp;38331 index row versions were removed.
&lt;br&gt;579 index pages have been deleted, 579 are currently reusable.
&lt;br&gt;CPU 0.66s/1.03u sec elapsed 68.38 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;rid_toode_idx&amp;quot; now contains 3275224 row versions in 31094 
&lt;br&gt;pages
&lt;br&gt;DETAIL: &amp;nbsp;38331 index row versions were removed.
&lt;br&gt;2290 index pages have been deleted, 2290 are currently reusable.
&lt;br&gt;CPU 1.39s/1.58u sec elapsed 333.82 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;rid_rtellimus_idx&amp;quot; now contains 3275230 row versions in 7390 
&lt;br&gt;pages
&lt;br&gt;DETAIL: &amp;nbsp;18591 index row versions were removed.
&lt;br&gt;0 index pages have been deleted, 0 are currently reusable.
&lt;br&gt;CPU 0.18s/0.66u sec elapsed 1.78 sec.
&lt;br&gt;INFO: &amp;nbsp;index &amp;quot;rid_toode_pattern_idx&amp;quot; now contains 3275230 row versions in 
&lt;br&gt;16310 pages
&lt;br&gt;DETAIL: &amp;nbsp;17800 index row versions were removed.
&lt;br&gt;0 index pages have been deleted, 0 are currently reusable.
&lt;br&gt;CPU 0.44s/1.04u sec elapsed 6.55 sec.
&lt;br&gt;INFO: &amp;nbsp;&amp;quot;rid&amp;quot;: removed 38331 row versions in 3090 pages
&lt;br&gt;DETAIL: &amp;nbsp;CPU 0.20s/0.10u sec elapsed 5.49 sec.
&lt;br&gt;INFO: &amp;nbsp;&amp;quot;rid&amp;quot;: found 38331 removable, 3275189 nonremovable row versions in 
&lt;br&gt;165282 pages
&lt;br&gt;DETAIL: &amp;nbsp;0 dead row versions cannot be removed yet.
&lt;br&gt;There were 1878923 unused item pointers.
&lt;br&gt;0 pages are entirely empty.
&lt;br&gt;CPU 5.06s/7.27u sec elapsed 607.59 sec.
&lt;br&gt;&lt;br&gt;Query returned successfully with no result in 1058319 ms.
&lt;br&gt;&lt;br&gt;&amp;gt; - what's the size of the dataset relative to the RAM ?
&lt;br&gt;&lt;br&gt;Db size is 7417 MB
&lt;br&gt;relevant table sizes in desc by size order:
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;40595 dok &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2345 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1214 pg_shdepend &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2259 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;40926 rid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2057 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1232 pg_shdepend_depender_index &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;795 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1233 pg_shdepend_reference_index &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 438 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 8 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44286 dok_tasudok_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 245 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44299 rid_toode_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 243 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;10 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44283 dok_klient_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;142 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;11 &amp;nbsp; &amp;nbsp; 19103791 rid_toode_pattern_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 127 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44298 rid_inpdokumnr_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;118 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44297 rid_dokumnr_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 110 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;43573 rid_pkey &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;109 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;18 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44288 dok_tasumata_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;91 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;19 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44289 dok_tellimus_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;89 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;20 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44284 dok_krdokumnr_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 89 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44285 dok_kuupaev_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 84 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;23 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;43479 dok_pkey &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;74 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;24 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;44282 dok_dokumnr_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 74 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;25 &amp;nbsp; &amp;nbsp; 19076304 rid_rtellimus_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 58 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;26 &amp;nbsp; &amp;nbsp; 18663923 dok_yksus_pattern_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 43 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;27 &amp;nbsp; &amp;nbsp; 18801591 dok_sihtyksus_pattern_idx &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 42 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;29 &amp;nbsp; &amp;nbsp; 18774881 dok_doktyyp &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30 MB
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;46 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;40967 toode &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13 MB
&lt;br&gt;&lt;br&gt;server is HP Proliant DL320 G3
&lt;br&gt;&lt;a href=&quot;http://h18000.www1.hp.com/products/quickspecs/12169_ca/12169_ca.HTML&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://h18000.www1.hp.com/products/quickspecs/12169_ca/12169_ca.HTML&lt;/a&gt;&lt;br&gt;CPU is 2.93Ghz Celeron 256kb cache.
&lt;br&gt;&lt;br&gt;Server has 2 GB RAM.
&lt;br&gt;It has SATA RAID 0,1 integrated controller (1.5Gbps) and SAMSUNG HD160JJ
&lt;br&gt;mirrored disks.
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; Now let's look more closely at the query :
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; explain analyze
&lt;br&gt;&amp;gt; SELECT sum(1)
&lt;br&gt;&amp;gt; &amp;nbsp; FROM dok JOIN rid USING (dokumnr)
&lt;br&gt;&amp;gt; &amp;nbsp; JOIN toode USING (toode)
&lt;br&gt;&amp;gt; &amp;nbsp; LEFT JOIN artliik using(grupp,liik)
&lt;br&gt;&amp;gt; &amp;nbsp; WHERE rid.toode='X05' AND dok.kuupaev&amp;gt;='2008-09-01'
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; I presume doing the query without artliik changes nothing to the runtime,
&lt;br&gt;&amp;gt; yes ?
&lt;/div&gt;&lt;br&gt;Yes. After removing artkliik from join I got response times 65 and 50
&lt;br&gt;seconds, so this does not make difference.
&lt;br&gt;&lt;br&gt;&amp;gt; Your problem here is that, no matter what, postgres will have to examine
&lt;br&gt;&amp;gt; - all rows where dok.kuupaev&amp;gt;='2008-09-01',
&lt;br&gt;&amp;gt; - and all rows where rid.toode = 'X05'.
&lt;br&gt;&amp;gt; If you use dok.kuupaev&amp;gt;='2007-09-01' (note : 2007) it will probably have
&lt;br&gt;&amp;gt; to scan many, many more rows.
&lt;br&gt;&lt;br&gt;Probably yes, since then it reads one year more sales data.
&lt;br&gt;&lt;br&gt;&amp;gt; If you perform this query often you could CLUSTER rid on (toode) and dok
&lt;br&gt;&amp;gt; on (kuupaev), but this can screw other queries.
&lt;br&gt;&lt;br&gt;Some reports are by sales date (dok.kuupaev) and customers.
&lt;br&gt;CLUSTER rid on (toode) slows them down. Also autovacuum cannot do 
&lt;br&gt;clustering.
&lt;br&gt;&lt;br&gt;&amp;gt; What is the meaning of the columns ?
&lt;br&gt;&lt;br&gt;This is typical sales data:
&lt;br&gt;&lt;br&gt;-- Receipt headers:
&lt;br&gt;DOK ( dokumnr &amp;nbsp;INT SERIAL PRIMARY KEY,
&lt;br&gt;&amp;nbsp; kuupaev DATE --- sales date
&lt;br&gt;)
&lt;br&gt;&lt;br&gt;-- Receipt details
&lt;br&gt;RID ( dokumnr INT,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;toode CHAR(20), &amp;nbsp;-- item code
&lt;br&gt;&amp;nbsp;CONSTRAINT rid_dokumnr_fkey FOREIGN KEY (dokumnr) &amp;nbsp; REFERENCES dok
&lt;br&gt;(dokumnr),
&lt;br&gt;&amp;nbsp; CONSTRAINT rid_toode_fkey FOREIGN KEY (toode)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; REFERENCES firma2.toode (toode)
&lt;br&gt;)
&lt;br&gt;&lt;br&gt;-- Products
&lt;br&gt;TOODE (
&lt;br&gt;&amp;nbsp; toode CHAR(20) PRIMARY KEY
&lt;br&gt;)
&lt;br&gt;&lt;br&gt;&amp;gt; To make this type of query faster I would tend to think about :
&lt;br&gt;&lt;br&gt;&amp;gt; - denormalization (ie adding a column in one of your tables and a
&lt;br&gt;&amp;gt; multicolumn index)
&lt;br&gt;&lt;br&gt;For this query it is possible to duplicate kuupaev column to rid table.
&lt;br&gt;However most of the this seems to go to scanning rid table, so I suspect
&lt;br&gt;that this will help.
&lt;br&gt;&lt;br&gt;&amp;gt; - materialized views
&lt;br&gt;&amp;gt; - materialized summary tables (ie. summary of sales for last month, for
&lt;br&gt;&amp;gt; instance)
&lt;br&gt;&lt;br&gt;There are about 1000 items and reports are different.
&lt;br&gt;&lt;br&gt;Andrus. 
&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20623163&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20623163.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20621409</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-21T05:49:24Z</published>
	<updated>2008-11-21T05:49:24Z</updated>
	<author>
		<name>Andrus Moor-2</name>
	</author>
	<content type="html">Richard,
&lt;br&gt;&lt;br&gt;&amp;gt; In addition to &amp;quot;top&amp;quot; below, you'll probably find &amp;quot;vmstat 5&amp;quot; useful.
&lt;br&gt;&lt;br&gt;Thank you.
&lt;br&gt;During this query run (65 sec), vmstat 5 shows big values in &amp;nbsp;bi,cs and wa 
&lt;br&gt;columns:
&lt;br&gt;&lt;br&gt;procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
&lt;br&gt;&amp;nbsp;r &amp;nbsp;b &amp;nbsp; swpd &amp;nbsp; free &amp;nbsp; buff &amp;nbsp;cache &amp;nbsp; si &amp;nbsp; so &amp;nbsp; &amp;nbsp;bi &amp;nbsp; &amp;nbsp;bo &amp;nbsp; in &amp;nbsp; &amp;nbsp;cs us sy id 
&lt;br&gt;wa
&lt;br&gt;&amp;nbsp;1 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; 88 &amp;nbsp;51444 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1854404 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;17 &amp;nbsp; &amp;nbsp; 6 &amp;nbsp; 15 &amp;nbsp; &amp;nbsp;13 &amp;nbsp;5 &amp;nbsp;1 83 
&lt;br&gt;10
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; 88 &amp;nbsp;52140 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1854304 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp;3626 &amp;nbsp; &amp;nbsp;95 &amp;nbsp;562 &amp;nbsp; 784 15 38 &amp;nbsp;0 
&lt;br&gt;47
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;51608 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1855668 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 14116 &amp;nbsp; 103 1382 &amp;nbsp;2294 &amp;nbsp;4 &amp;nbsp;8 &amp;nbsp;0 
&lt;br&gt;88
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;51620 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1857256 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;1 15258 &amp;nbsp; &amp;nbsp;31 1210 &amp;nbsp;1975 &amp;nbsp;4 &amp;nbsp;8 &amp;nbsp;0 
&lt;br&gt;88
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;2 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;50448 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1859188 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 13118 &amp;nbsp; &amp;nbsp;19 1227 &amp;nbsp;1982 &amp;nbsp;3 &amp;nbsp;7 &amp;nbsp;0 
&lt;br&gt;90
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;51272 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1859088 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp;7691 &amp;nbsp; &amp;nbsp;53 &amp;nbsp;828 &amp;nbsp;1284 14 &amp;nbsp;4 &amp;nbsp;0 
&lt;br&gt;82
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;52472 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1858792 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 10691 &amp;nbsp; &amp;nbsp; 9 &amp;nbsp;758 &amp;nbsp; 968 &amp;nbsp;3 &amp;nbsp;7 &amp;nbsp;0 
&lt;br&gt;89
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;2 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;51240 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1858596 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp;8204 &amp;nbsp;7407 &amp;nbsp;717 &amp;nbsp;1063 &amp;nbsp;2 &amp;nbsp;5 &amp;nbsp;0 
&lt;br&gt;93
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;51648 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1860388 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 20622 &amp;nbsp; 121 1118 &amp;nbsp;2229 12 &amp;nbsp;9 &amp;nbsp;0 
&lt;br&gt;79
&lt;br&gt;&amp;nbsp;2 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;50564 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1861396 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 20994 &amp;nbsp;3277 &amp;nbsp;969 &amp;nbsp;1681 15 &amp;nbsp;8 &amp;nbsp;0 
&lt;br&gt;76
&lt;br&gt;&amp;nbsp;1 &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;52180 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1860192 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 18542 &amp;nbsp; &amp;nbsp;36 &amp;nbsp;802 &amp;nbsp;1276 36 12 &amp;nbsp;0 
&lt;br&gt;51
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;91872 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1820948 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;1 15285 &amp;nbsp; &amp;nbsp;47 &amp;nbsp;588 &amp;nbsp; 774 &amp;nbsp;9 12 32 
&lt;br&gt;47
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;91904 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1820948 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; 4 &amp;nbsp;251 &amp;nbsp; &amp;nbsp;18 &amp;nbsp;0 &amp;nbsp;0 
&lt;br&gt;100 &amp;nbsp;0
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;92044 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1820948 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp;250 &amp;nbsp; &amp;nbsp;17 &amp;nbsp;0 &amp;nbsp;0 
&lt;br&gt;100 &amp;nbsp;0
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;91668 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1821156 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;27 &amp;nbsp; &amp;nbsp;93 &amp;nbsp;272 &amp;nbsp; &amp;nbsp;66 &amp;nbsp;5 &amp;nbsp;0 92 
&lt;br&gt;3
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;91668 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1821156 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp;64 &amp;nbsp;260 &amp;nbsp; &amp;nbsp;38 &amp;nbsp;0 &amp;nbsp;0 
&lt;br&gt;100 &amp;nbsp;0
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;91636 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1821156 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; 226 &amp;nbsp;277 &amp;nbsp; &amp;nbsp;71 &amp;nbsp;0 &amp;nbsp;0 
&lt;br&gt;100 &amp;nbsp;0
&lt;br&gt;&amp;nbsp;0 &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 92 &amp;nbsp;91676 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 1821156 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp;26 &amp;nbsp;255 &amp;nbsp; &amp;nbsp;23 &amp;nbsp;0 &amp;nbsp;0 
&lt;br&gt;100 &amp;nbsp;0
&lt;br&gt;&lt;br&gt;&amp;gt; Here you're stuck waiting for disks (91.0% wa). Check out vmstat and
&lt;br&gt;&amp;gt; iostat to see what's happening.
&lt;br&gt;&lt;br&gt;typing &amp;nbsp;iostat returns
&lt;br&gt;&lt;br&gt;bash: iostat: command not found
&lt;br&gt;&lt;br&gt;It seems that this is not installed in this gentoo.
&lt;br&gt;&lt;br&gt;Andrus. 
&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20621409&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Hash-join-on-int-takes-8..114-seconds-tp20588810p20621409.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20613703</id>
	<title>Re: Performance and IN clauses</title>
	<published>2008-11-20T17:09:36Z</published>
	<updated>2008-11-20T17:09:36Z</updated>
	<author>
		<name>tv-8</name>
	</author>
	<content type="html">Mark Roberts napsal(a):
&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; On Tue, 2008-11-18 at 17:38 +0100, &lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20613703&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;tv@...&lt;/a&gt; wrote:
&lt;br&gt;&amp;gt;&amp;gt; I bet there is no 'critical' length - this is just another case of
&lt;br&gt;&amp;gt;&amp;gt; index
&lt;br&gt;&amp;gt;&amp;gt; scan vs. seqscan. The efficiency depends on the size of the table /
&lt;br&gt;&amp;gt;&amp;gt; row,
&lt;br&gt;&amp;gt;&amp;gt; amount of data in the table, variability of the column used in the IN
&lt;br&gt;&amp;gt;&amp;gt; clause, etc.
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; Splitting the query with 1000 items into 10 separate queries, the
&lt;br&gt;&amp;gt;&amp;gt; smaller
&lt;br&gt;&amp;gt;&amp;gt; queries may be faster but the total time consumed may be actually
&lt;br&gt;&amp;gt;&amp;gt; higher.
&lt;br&gt;&amp;gt;&amp;gt; Something like
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; 10 * (time of small query) + (time to combine them) &amp;gt; (time of large
&lt;br&gt;&amp;gt;&amp;gt; query)
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; If the performance of the 'split' solution is actually better than the
&lt;br&gt;&amp;gt;&amp;gt; original query, it just means that the planner does not use index scan
&lt;br&gt;&amp;gt;&amp;gt; when it actually should. That means that either
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; (a) the planner is not smart enough
&lt;br&gt;&amp;gt;&amp;gt; (b) it has not current statistics of the table (run ANALYZE on the
&lt;br&gt;&amp;gt;&amp;gt; table)
&lt;br&gt;&amp;gt;&amp;gt; (c) the statistics are not detailed enough (ALTER TABLE ... SET
&lt;br&gt;&amp;gt;&amp;gt; STATICTICS)
&lt;br&gt;&amp;gt;&amp;gt; (d) the cost variables are not set properly (do not match the hardware
&lt;br&gt;&amp;gt;&amp;gt; -
&lt;br&gt;&amp;gt;&amp;gt; decreate index scan cost / increase seq scan cost)
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; regards
&lt;br&gt;&amp;gt;&amp;gt; Tomas
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; I know that it's much faster (for us) to run many smaller queries than
&lt;br&gt;&amp;gt; one large query, and I think that it's primarily because of your reason
&lt;br&gt;&amp;gt; a. &amp;nbsp;Most of our problems come from Pg misunderstanding the results of a
&lt;br&gt;&amp;gt; join and making a bad plan decision. &amp;nbsp;Batching dramatically reduces the
&lt;br&gt;&amp;gt; liklihood of this.
&lt;/div&gt;&lt;br&gt;As I already said - even the smartest planner won't work without correct 
&lt;br&gt;input data. Have you tried fixing the points (b), (c) and (d)?
&lt;br&gt;&lt;br&gt;Fixing them might improve the planner performance so that you don't need 
&lt;br&gt;the batchning at all.
&lt;br&gt;&lt;br&gt;regards
&lt;br&gt;Tomas
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Sent via pgsql-performance mailing list (&lt;a href=&quot;http://www.nabble.com/user/SendEmail.jtp?type=post&amp;post=20613703&amp;i=1&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;pgsql-performance@...&lt;/a&gt;)
&lt;br&gt;To make changes to your subscription:
&lt;br&gt;&lt;a href=&quot;http://www.postgresql.org/mailpref/pgsql-performance&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.postgresql.org/mailpref/pgsql-performance&lt;/a&gt;&lt;br&gt;</content>
	<link rel="alternate" type="text/html" href="http://www.nabble.com/Performance-and-IN-clauses-tp20562289p20613703.html" />
</entry>

<entry>
	<id>tag:www.nabble.com,2006:post-20601379</id>
	<title>Re: Hash join on int takes 8..114 seconds</title>
	<published>2008-11-20T05:46:11Z</published>
	<updated>2008-11-20T05:46:11Z</updated>
	<author>
		<name>PFC-2</name>
	</author>
	<content type="html">&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; OK so vmstat says you are IO-bound, this seems logical if the same plan &amp;nbsp;
&lt;br&gt;has widely varying timings...
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Let's look at the usual suspects :
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; - how many dead rows in your tables ? are your tables data, or bloat ? &amp;nbsp;
&lt;br&gt;(check vacuum verbose, etc)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; - what's the size of the dataset relative to the RAM ?
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &