Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TMmij-0003zi-Pr for pgsql-bugs@postgresql.org; Fri, 12 Oct 2012 21:24:37 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TMmif-0003fu-SE for pgsql-bugs@postgresql.org; Fri, 12 Oct 2012 21:24:37 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q9CLOVFj022734; Fri, 12 Oct 2012 17:24:32 -0400 (EDT) From: Tom Lane To: vaclav.juza@xitee.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #7598: Loss of view performance after dump/restore of the view definition In-reply-to: References: Comments: In-reply-to vaclav.juza@xitee.com message dated "Thu, 11 Oct 2012 11:29:39 -0000" Date: Fri, 12 Oct 2012 17:24:31 -0400 Message-ID: <22733.1350077071@sss.pgh.pa.us> X-Pg-Spam-Score: -4.0 (----) X-Archive-Number: 201210/112 X-Sequence-Number: 34412 vaclav.juza@xitee.com writes: > when a view (with the below properites) is dump and restored (no matter if > using pg_dump, copied from pg_admin or using pg_views) it's performance is > worse than before. The view was using tables with columns of type "character > varying(xx)" and the dump inserts "::text" casts into the join conditions on > these columns. This is not the dump code's fault: those casts are legitimate, and indeed present in the original view anyway. However, the planner was having a problem with thinking that implicit and explicit casts weren't equivalent. I've committed a fix into 9.2. I'm hesitant to change the behavior further back than that, even though arguably this has been broken since 8.3. > In the real case we faced this problem, the performance loss was much higher > on PostgreSQL 9.2.1 (3 seconds vs. 3 minutes) than on 9.1.4 (1.3 seconds vs. > 7 seconds) and both variants were slower on 9.2.1 than on 9.1.4. In the test > case below the behaviour is similar on both Postgres version. It's difficult to tell whether there's any real issue here beyond that. I sometimes get a noticeably slower plan out of HEAD, but sometimes I don't, if I regenerate the random table contents. It looks to me like the slower plans occur when it changes the join ordering, but that's contingent on rowcount estimates that are equally awful in both versions; the lvl = (SELECT max/min(lvl) ...) conditions are not estimated well by any existing Postgres release. So I'm not inclined to ascribe a lot of significance to the planner's choices here. regards, tom lane