Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VHz6u-0002YB-I3 for pgsql-performance@arkaria.postgresql.org; Fri, 06 Sep 2013 16:42:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VHz6t-0002Tg-Qp for pgsql-performance@arkaria.postgresql.org; Fri, 06 Sep 2013 16:42:15 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VHz6s-0002SK-Pp for pgsql-performance@postgresql.org; Fri, 06 Sep 2013 16:42:14 +0000 Received: from mail-ob0-f171.google.com ([209.85.214.171]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VHz6p-0005Zd-3z for pgsql-performance@postgresql.org; Fri, 06 Sep 2013 16:42:13 +0000 Received: by mail-ob0-f171.google.com with SMTP id tb18so3747486obb.30 for ; Fri, 06 Sep 2013 09:42:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=TTbsc+xsCU+8ciJ+oZE9oQKSub+wL7hO2DQuJT+LK5s=; b=glpdPSbYG40YYhk0hK/4hAHNlwpfJ2wOYtKk99YgDPurRxJCqc6GnWo9VLjB3/Pddg ajDQZ7yiB3LDwf0rdIJPgAj5h3Nd1Lmz05fM2+Llzuos1IkAinN84/bOIlQ1xinn9du5 vJQQZu9Yf0tr5qjLt4s/S9d7wxvhXtIyBLA51j2QDmRJDeBtyRW/UZ3gKNAVvenXEK/Q bHJ0fZ4lTFCWgFMjuUFsRViKvGE+zE48MEinPw2SUUbKsPNVD17bH8ionzaF4lpulohF 3Pydd6Nq15j8NP2luoV4c4sp81BviNjV7LKWiCuDEmXTpztUYmQ2BwXYCeeh6jeu2Pvb 0Vmg== X-Gm-Message-State: ALoCoQlA22yv1+xYTRCiLZntT0XP/k4Hby0m7KpCrlky3iZyBQTam+75cKQ59/9vAosBBfbW2xIJ X-Received: by 10.60.124.14 with SMTP id me14mr2548260oeb.4.1378485730523; Fri, 06 Sep 2013 09:42:10 -0700 (PDT) Received: from brianf.consistentstate.com (216-98-193-98.static.forethought.net. [216.98.193.98]) by mx.google.com with ESMTPSA id z5sm3141156obg.13.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 06 Sep 2013 09:42:10 -0700 (PDT) Message-ID: <522A05E1.1070103@consistentstate.com> Date: Fri, 06 Sep 2013 10:42:09 -0600 From: Brian Fehrle User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130311 Thunderbird/17.0.4 MIME-Version: 1.0 To: Tom Lane CC: pgsql-performance@postgresql.org Subject: Re: View with and without ::text casting performs differently. References: <5229097C.4070401@consistentstate.com> <1960.1378425018@sss.pgh.pa.us> In-Reply-To: <1960.1378425018@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 09/05/2013 05:50 PM, Tom Lane wrote: > Brian Fehrle writes: >> I have a view, that when created with our create statement works >> wonderfully, a query on the view with a standard where clause that >> narrows the result to a single row performs in under a single ms. >> However, when we export this view and re-import it (dump and restore of >> the database, which happens often), the exported version of the view has >> been modified by Postgres to include various typecasting of some columns >> to text. > This is normal (varchar doesn't actually have any operations of its own). > >> All columns that it typecasts to text are varchar(20), so there is >> nothing wrong in what it's doing there. However, with the view >> definition including the ::text casting, the query planner changes and >> it goes into a nested loop, taking a query from <1ms to over ten minutes. > I rather doubt that the now-explicit-instead-of-implicit casts have much > to do with that. It seems more likely that you forgot to re-ANALYZE in > the new database, or there are some different planner settings, or > something along that line. I have two versions of the view in place on the same server, one with the typecasting and one without, and this is where I see the differences (no ::text runs in 0.5ms and with ::text runs in 13 or so minutes with nested loop), so it's all running off the same statistics on the data. Running an analyse on all tables involved did not change the query plan on the 'bad' version of the view (default_statistics_target = 400) - Brian F > > regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance