Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jLgKo-00055f-4C for pgsql-performance@arkaria.postgresql.org; Tue, 07 Apr 2020 04:59:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jLgKm-00041X-W1 for pgsql-performance@arkaria.postgresql.org; Tue, 07 Apr 2020 04:59:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jLgKm-00041Q-Oo for pgsql-performance@lists.postgresql.org; Tue, 07 Apr 2020 04:59:36 +0000 Received: from mail-qv1-xf43.google.com ([2607:f8b0:4864:20::f43]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jLgKk-0000z0-0g for pgsql-performance@postgresql.org; Tue, 07 Apr 2020 04:59:36 +0000 Received: by mail-qv1-xf43.google.com with SMTP id p60so1256978qva.5 for ; Mon, 06 Apr 2020 21:59:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=mu4WFNm9ljv0+pyJ/MxYim1TF7pcuSaFMfa114/9mfA=; b=qRXV3BsmZFjzf6WHJP4czI6KipY8WfuHnrd+AhR33r6jbb+Bt5UgIH4ukOYlBzNX5o iFtv3vlq7dkqP41D5LCiz0vTIPgaLaTdm25tMhUxJCvPwhgsN3EAZYDToxpHGYfFF8ed MTtdXXbq6Zu/8SThZ85Z4Yp58KX1c4lVI7y/+kmaQWFESe8FB/c5rL5wIz5RZdBXRQHS tmgHQaoYccHQGT8h77APT30bdD2V1CsWIEm6KMH5+9QthakcyA7XRRTeYY4bNMn9RQMe LZbVCAn4UyVgJrYRGXNb2G2NZE1n6whSNt+KuY+JA4OH0hVgHQ9PsW4cuK4Fjato3a6u z2Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=mu4WFNm9ljv0+pyJ/MxYim1TF7pcuSaFMfa114/9mfA=; b=Cz6CDrB7G6wkVDz5nTUv84BEKN8K81s9/dbIGwMzxfRznB2gwjR+AmG9TPcRsbLxhH FLDmLLqdoSJLRrOvIioyJT7wrZPMf8dVZ7OdIp3W2vFSu8PhWTIV+q2riEHgFjXa8Ufn oqgKb5RNDFPXy9t+wWIABCtvZ08Li9JT8AFcfr5nFhbR3t3AQlCnojd+6Kt/HwyizCrN LSJ7PfIgUokls/e2ngyN44uo/hahijZg9N6LJJutHh51jXqGdgk1fbJFyyBDUnqiN4Dj iRTGWzM1Hp+APhK5mUFW3yirRL2jZKqpMgLCvFciAJ1mo+IpXgUw7GX7qhTbBkBCOSGX lUzA== X-Gm-Message-State: AGi0PuZEmX2DQko5peXoYWTuWPcUk0qvigAP+pRdZW6xujx6kI1XlFa9 kWAe42YZvr3e26FIVe8NVa/Ex0ZPmvc= X-Google-Smtp-Source: APiQypKY5lLcCv1XfaDf0p17Wjp7Kztvc5XkmTghkidz4uNE1WNQ3WmK0pGAqNpK8cLNhH95ffYgow== X-Received: by 2002:a0c:a8c4:: with SMTP id h4mr519174qvc.72.1586235572080; Mon, 06 Apr 2020 21:59:32 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id c23sm3283771qka.46.2020.04.06.21.59.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2020 21:59:31 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 0F6F58007F7; Mon, 6 Apr 2020 23:59:30 -0500 (CDT) Date: Mon, 6 Apr 2020 23:59:29 -0500 From: Justin Pryzby To: Rick Vincent Cc: pgsql-performance@postgresql.org, Manoj Kumar , Herve Aubert Subject: Re: Postgres not using index on views Message-ID: <20200407045929.GJ2228@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Apr 06, 2020 at 02:19:59PM +0000, Rick Vincent wrote: > I am seeing a performance problem with postgresql v 11.7 on views, and I am wondering if anyone can tell me why or has any suggestion. > > A table is created as: > > CREATE TABLE "FBNK_CUSTOMER" (RECID VARCHAR(255) NOT NULL PRIMARY KEY, XMLRECORD VARCHAR) > > And contains only 180 rows. > > Doing an explain plan on the view created over this gives: > > EXPLAIN ANALYZE > select RECID from "V_FBNK_CUSTOMER" > > > Subquery Scan on "V_FBNK_CUSTOMER" (cost=0.00..19014.60 rows=180 width=7) (actual time=459.601..78642.189 rows=180 loops=1) > -> Seq Scan on "FBNK_CUSTOMER" a (cost=0.00..19012.80 rows=180 width=14575) (actual time=459.600..78641.950 rows=180 loops=1) > > Yet an Explain plan on the underlying table( on select RECID from "FBNK_CUSTOMER") gives: > > Seq Scan on "FBNK_CUSTOMER" (cost=0.00..22.80 rows=180 width=7) (actual time=0.004..0.272 rows=180 loops=1) It still did a seq scan on the table, so I'm not sure what this has to do with index scans ? > The following query takes an extremely long time for only 180 rows, and what this means is that we would have to index anything appearing in the where clause for every table in order to use views because the views seem not to consider the select clause. Why is that and does anyone know a way around this? Is there a reason why you don't store the extracted value in its own column ? And maybe keep it up to date using an insert/update trigger on the xmlrecord column. -- Justin