Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TEbgq-0008Bp-J3 for pgsql-bugs@postgresql.org; Thu, 20 Sep 2012 08:00:52 +0000 Received: from mail-pb0-f46.google.com ([209.85.160.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TEbgo-000843-Bi for pgsql-bugs@postgresql.org; Thu, 20 Sep 2012 08:00:51 +0000 Received: by pbbrr13 with SMTP id rr13so4503702pbb.19 for ; Thu, 20 Sep 2012 01:00:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=7Tem2aoRVBvL7QEItvSua/qZFGoYVjcCGEHHnLS3VkY=; b=CM/pPh8Y6Z9+xh/68OOrCbZHowPzuTXKUJv2ftXKs8wPLciroMiCVTj+r2AP6LiMSA ycmixqQQqnSzM3EXahaiR+SoufOrVhFV1M5tBQwuCmGI50U80oASBV2KMTO8zKMi8Yto h5q3oSFr1E34Sd9lWjtG9Z5q+MEXwBqLtkKf+kO5owHyBYc7H17gWCrihPEAuiPVYjro E1DqmxoVyivuXJ805PLoKLUJo0hoIVmAZu69iQHNis95m7XqjYC28MhtIMuLqsK0yyyV kQ5oEMAUEOxSXy3MQlhRDu1B2icWdgzP3BBMpFvg/Z4REgqLOojxquReH9UnM6/3iBo9 zDkQ== Received: by 10.68.220.137 with SMTP id pw9mr4740893pbc.1.1348128048292; Thu, 20 Sep 2012 01:00:48 -0700 (PDT) Received: from ayaki.localdomain (office1.postnewspapers.com.au. [150.101.171.128]) by mx.google.com with ESMTPS id vd4sm3151203pbc.41.2012.09.20.01.00.45 (version=SSLv3 cipher=OTHER); Thu, 20 Sep 2012 01:00:47 -0700 (PDT) Message-ID: <505ACD2A.5080503@ringerc.id.au> Date: Thu, 20 Sep 2012 16:00:42 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0 MIME-Version: 1.0 To: l1t@tom.com CC: pgsql-bugs@postgresql.org Subject: Re: BUG #7556 addition info References: <505AA630.000163.01369@bjapp23> In-Reply-To: <505AA630.000163.01369@bjapp23> Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQmpte5LBNJ22v2WtWaivXt1+55jIxSEMYvjDg8OWWh7sLyFHAbUA7GCfSQDO4vIck3uZdFk X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201209/226 X-Sequence-Number: 34220 On 09/20/2012 01:14 PM, l1t@tom.com wrote: > plan of http://archives.postgresql.org/pgsql-bugs/2012-09/msg00222.php > test=# explain select max(a.info)from sli_test a where a.id not > in(select b.id from sli_test2 b where b.id<50000); > QUERY PLAN > --------------------------------------------------------------------------------------- > Aggregate (cost=9243466274.00..9243466274.01 rows=1 width=12) > -> Seq Scan on sli_test a (cost=0.00..9243465024.00 rows=500000 > width=12) > Filter: (NOT (SubPlan 1)) > SubPlan 1 > -> Materialize (cost=0.00..18359.60 rows=50919 width=4) > -> Seq Scan on sli_test2 b (cost=0.00..17906.00 > rows=50919 width=4) > Filter: (id < 50000) That takes about 500ms here, on 9.1. What did you expect? What's the EXPLAIN ANALYZE if your results differ? You've failed to show your NOT EXISTS query and plan for comparison, but I'm guessing: regress=# explain analyze select max(a.info)from sli_test a where not exists (select 1 from sli_test2 b where a.id=b.id and b.id<50000); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------ Aggregate (cost=50256.22..50256.23 rows=1 width=12) (actual time=671.993..671.993 rows=1 loops=1) -> Hash Anti Join (cost=18510.11..47877.04 rows=951671 width=12) (actual time=103.048..459.508 rows=950001 loops=1) Hash Cond: (a.id = b.id) -> Seq Scan on sli_test a (cost=0.00..16274.00 rows=1000000 width=16) (actual time=0.016..71.871 rows=1000000 loops=1) -> Hash (cost=17906.00..17906.00 rows=48329 width=4) (actual time=86.948..86.948 rows=49999 loops=1) Buckets: 8192 Batches: 1 Memory Usage: 1758kB -> Seq Scan on sli_test2 b (cost=0.00..17906.00 rows=48329 width=4) (actual time=0.018..76.489 rows=49999 loops=1) Filter: (id < 50000) Total runtime: 672.379 ms (9 rows) which, if so performs signficiantly worse. I'm struggling to understand what exactly your complaint is. It's kind of hard to work out what the intention of the query is in real-world terms to suggest alternatives, too. -- Craig Ringer