X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 96ACAD8E1F for ; Sat, 24 Sep 2005 00:09:18 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 86027-01 for ; Sat, 24 Sep 2005 03:09:16 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 72DD3D6E40 for ; Sat, 24 Sep 2005 00:09:13 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j8O399VT008873; Fri, 23 Sep 2005 23:09:10 -0400 (EDT) To: eVl Cc: pgsql-performance@postgresql.org Subject: Re: optimization downgrade perfomance? In-reply-to: <652316563.20050923212351@gmail.com> References: <133614678.20050923012716@gmail.com> <3192.1127482808@sss.pgh.pa.us> <652316563.20050923212351@gmail.com> Comments: In-reply-to eVl message dated "Fri, 23 Sep 2005 21:23:51 +0300" Date: Fri, 23 Sep 2005 23:09:09 -0400 Message-ID: <8872.1127531349@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200509/319 X-Sequence-Number: 14627 eVl writes: >> You tell us --- let's see EXPLAIN ANALYZE results for both cases. > Here EXPLAIN ANALYZE results for both queries attached. The problem seems to be that the is_uaix() function is really slow (somewhere around 4 msec per call it looks like). Look at the first scan over stats: -> Index Scan using cdate_cluster on stats s (cost=0.00..201.51 rows=6 width=25) (actual time=5.231..2165.145 rows=418 loops=1) Index Cond: (cdate = '2005-09-01'::date) Filter: ((fromip << '192.168.0.0/16'::inet) AND (NOT (toip << '192.168.0.0/16'::inet)) AND (CASE is_uaix(toip) WHEN true THEN 'local'::text ELSE 'global'::text END = 'global'::text)) versus -> Index Scan using cdate_cluster on stats s (cost=0.00..165.94 rows=1186 width=25) (actual time=0.131..43.258 rows=578 loops=1) Index Cond: (cdate = '2005-09-01'::date) Filter: ((fromip << '192.168.0.0/16'::inet) AND (NOT (toip << '192.168.0.0/16'::inet))) The 578 evaluations of the CASE are adding over 2100msec. There's another 1600 evaluations needed in the other arm of the UNION... Better look at exactly what is_uaix() is doing, because the CASE structure is surely not that slow. regards, tom lane