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 1mILOY-00066q-3u for pgsql-performance@arkaria.postgresql.org; Tue, 24 Aug 2021 01:38:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mILOU-0006PO-P0 for pgsql-performance@arkaria.postgresql.org; Tue, 24 Aug 2021 01:38:26 +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 1mILOU-0006PE-D3 for pgsql-performance@lists.postgresql.org; Tue, 24 Aug 2021 01:38:26 +0000 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mILOR-0001TA-L9 for pgsql-performance@lists.postgresql.org; Tue, 24 Aug 2021 01:38:25 +0000 Received: by mail-il1-x133.google.com with SMTP id v2so18954457ilg.12 for ; Mon, 23 Aug 2021 18:38:22 -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=g2GAk9ZR0vDH9txgvAQf6u/5TaJ+bApd41CbZHXqsC0=; b=JM1RYk4CfLAQduQlyGo0G0ebhfJwcy3rjM3dKXk5dtEXi9jHU3FkuiXcd+Ys8ZKusR cpNB9e++4NgsouVYwVP/M8T344Xk4jNkP37NZzB8U1R40eHYeRt2wMYRYWsT41F934Z9 sAtJvyI8Opkun152NbrbvhOZ+xsclDUix8aalb8P/vCyC6ZUsC0VoTcB7rDm2VuTtTtp bj0XbDbQFvgjmT6nOslhRCMQFSSHXUguCnLyUErp81JlHfk50ReQvYtoji417MxHmP3W 5YAkOnpmVe/pUvtjlCWBymmn8ZykzS0lWBXjpHyerzJj7D+ynX+AZLAQZa6QCI3pygGN SpwA== 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=g2GAk9ZR0vDH9txgvAQf6u/5TaJ+bApd41CbZHXqsC0=; b=eEVyBdk2HgtIVly80IjjcuY966X1dvYLjDrpHqbTj/nYbOvsAfSCNDH/pVVA8koXA2 u67/2lMVZo0pcgnn8FZACN6VamjBysfDnX1WpXxLtUwKoi1mP/7bqQqiW/PJCrFMlBLX ktpIrZJKfU0LL8RuCL4j3vGtIVcMFzNdKSbplJYoFJIcfcUJXx2Vy3Mhned5P9i/jaaz kZi+WB2dOE1tkZ4neRtZfvtOK2AooQCbxdNSapLqoJS59bwkzysU3XKwl1+6LQ3GJQ2W Kg1sXvCMSqMkZRGJFc8daw/vhiVXMfCOPwmETQaf0enaCdeq1rA5ZrSYHIem/BhuLQdS 7vDw== X-Gm-Message-State: AOAM531ste3M6qYNAGTM5f5aIVpSh5pXv5xuUTIv1HcbOCA7bWAYNJCx 8tCyd+j+vix5Js2IAXQ8thKbMY+vSM2ajg== X-Google-Smtp-Source: ABdhPJw88izsQZHGX3gpRbnKr5qlb7Jqma3q6yvKNSAEGlaNLPAGVcyZ3KPav37emUas7UJbP2nfyA== X-Received: by 2002:a05:6e02:1288:: with SMTP id y8mr24560428ilq.206.1629769101439; Mon, 23 Aug 2021 18:38:21 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id u16sm9162818iob.41.2021.08.23.18.38.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Aug 2021 18:38:21 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id C7317800870; Mon, 23 Aug 2021 20:38:19 -0500 (CDT) Date: Mon, 23 Aug 2021 20:38:19 -0500 From: Justin Pryzby To: Matt Dupree Cc: pgsql-performance@lists.postgresql.org Subject: Re: Postgres using the wrong index index Message-ID: <20210824013819.GK10479@telsasoft.com> References: <20210811123856.GE10479@telsasoft.com> <20210812034510.GG10479@telsasoft.com> <20210812232006.GN10479@telsasoft.com> <20210817185232.GN10479@telsasoft.com> 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: Archived-At: Precedence: bulk On Mon, Aug 23, 2021 at 08:53:15PM -0400, Matt Dupree wrote: > Is it possible that the row estimate is off because of a column other than > time? I would test this by writing the simplest query that reproduces the mis-estimate. > I looked at the # of events in that time period and 1.8 million is > actually a good estimate. What about the > ((strpos(other_events_1004175222.hierarchy, '#close_onborading;'::text) <> > 0) condition in the filter? It makes sense that Postgres wouldn't have a > way to estimate how selective this condition is. The issue I see is here. I don't know where else I'd start but to understand this. | Index Scan using other_events_1004175222_pim_evdef_67951aef14bc_idx on public.other_events_1004175222 (cost=0.28..1,648,877.92 ROWS=1,858,891 width=32) (actual time=1.008..15.245 ROWS=23 loops=1) | Output: other_events_1004175222.user_id, other_events_1004175222."time", other_events_1004175222.session_id | Index Cond: ((other_events_1004175222."time" >= '1624777200000'::bigint) AND (other_events_1004175222."time" <= '1627369200000'::bigint)) | Buffers: shared read=25 This has no "filter" condition, it's a "scan" node with bad over-estimate. Note that this is due to the table's column stats, not any index's stats, so every plan is affected. even though some happen to work well. The consequences of over-estimates are not as terrible as for under-estimates, but it's bad to start with inputs that are off by 10^5. -- Justin