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 1jyDri-0002p5-8E for pgsql-performance@arkaria.postgresql.org; Wed, 22 Jul 2020 12:28:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jyDrg-0007dk-Th for pgsql-performance@arkaria.postgresql.org; Wed, 22 Jul 2020 12:28:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jyDrg-0007dd-IQ for pgsql-performance@lists.postgresql.org; Wed, 22 Jul 2020 12:28:52 +0000 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jyDrd-0007kD-SM for pgsql-performance@lists.postgresql.org; Wed, 22 Jul 2020 12:28:51 +0000 Received: by mail-io1-xd2c.google.com with SMTP id q74so2352540iod.1 for ; Wed, 22 Jul 2020 05:28:49 -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=4j2JjwPSRntgjhCEylG/iIhl2C9Ndsvp3EGz9Utg56Y=; b=fFiHCKuuxzzHGrRR4AIJZV/Rg4nr4vw+vg1GrJEWCSgrUb3RiPE+jdeh0aIpLEEiz9 mkhsdyQOhjvP1yg8eMQ4y6+fkb78mUmb4Uz72G8kXs8mtjduZnlnJSmHnLA+3qOJvtdm 1uwoaVeCpPkP7t2vM/zzkiyVe68cvLoNMyfOTRQox4EWbGEbAVxCTcFgXGtg3hAhcH/B MGuG7uklkTWEF3UqSmKYiakGPuodG3fCr6xnVAjstyFnd1BYMNlSWvAM1q2pdgt1w0u4 ovQcUoi7JI1de/NKDDyqlOcZcwmegjUuFOVbwm7Z98H0KJlPYIjaAMwcl3//7+KTP4B7 O5hQ== 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=4j2JjwPSRntgjhCEylG/iIhl2C9Ndsvp3EGz9Utg56Y=; b=q41GBZ/vwdv1NXNBL7LkXtCVEOWaqk7jT8FmFp7IAbsr+YKdLQgpkcXhB+wXVOP7xr yJghfs+eYkp5hMgVPwitUosxUkPsCDbDCLWCEPDTU0s2yi64pAw9Yd7IyHKhkZ9peD/g 9jrM49mC1uUjulW3DZqrtZmSRP87oDgZYVi8oWMX9mPcPffetHA4xGjNWNXK+ylys9VN 0WT+OJdbIt44hlVUnFBYAOuEC+LewJhuW5EFSDEZIVE7QujSi25NO8wAEA0U8E+OfXvZ W5Vt79/6LOXo4IEn+UKZ5xvy3iNUxBhuTxMX10xlAJR2NXQ6GcCZrb+wlJ3ujy7Bxysl npDw== X-Gm-Message-State: AOAM532WwmzZl8PTCyMsGbzq2jlEvGdTPOyBvPV0XZKd6QL1fBOz7QGd SWKYFDNW2v7ow/7jvlGF/XX2lzLmgVg= X-Google-Smtp-Source: ABdhPJzoe9zzyrD97MWqHTlPpUCSi50zc0hxgu9DAeCij49KgBqU7d7LrRpoKYRXW/Wd0MQ/M3KYTw== X-Received: by 2002:a05:6638:1513:: with SMTP id b19mr8709031jat.109.1595420929077; Wed, 22 Jul 2020 05:28:49 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id u3sm11947804iol.41.2020.07.22.05.28.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Jul 2020 05:28:48 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 32532800173; Wed, 22 Jul 2020 07:28:47 -0500 (CDT) Date: Wed, 22 Jul 2020 07:28:47 -0500 From: Justin Pryzby To: Julian Wolf Cc: pgsql-performance Postgres Mailing List Subject: Re: Too few rows expected by Planner on partitioned tables Message-ID: <20200722122846.GS5748@telsasoft.com> References: <20200721172713.GJ5748@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: Precedence: bulk On Wed, Jul 22, 2020 at 06:33:17AM +0000, Julian Wolf wrote: > Hello Justin, > > > thank you very much for your fast response. > > > Is there a correlation between daterange and spacial_feature_id ? > > I am not entirely sure, what you mean by that. Basically, no, they are not correlated - spatial features are places on a map, date ranges are time periods. But, as they are both part of a primary key in this particular table, they are correlated in some way as to be a part of uniquely identifying a row. > > > > Are the estimates good if you query on *only* daterange? spacial_feature_id ? > Unfortunately no, they are not: I checked and found that range types don't have "normal" statistics, and in particular seem to use a poor ndistinct estimate.. /* Estimate that non-null values are unique */ stats->stadistinct = -1.0 * (1.0 - stats->stanullfrac); You could try to cheat and hardcode a different ndistinct that's "less wrong" by doing something like this: ALTER TABLE t ALTER a SET (N_DISTINCT=-0.001); ANALYZE t; Maybe a better way is to create an index ON: lower(range),upper(range) And then query: WHERE (lower(a),upper(a)) = (1,112); Since you'd be storing the values separately in the index anyway, maybe this means that range types won't work well for you for primary, searchable columns. But if you're stuck with the schema, another kludge, if you want to do something extra weird, is to remove statistics entirely by disabling autoanalyze on the table and then manually run ANALYZE(columns) where columns doesn't include the range column. You'd have to remove the stats: begin; DELETE FROM pg_statistic s USING pg_attribute a WHERE s.staattnum=a.attnum AND s.starelid=a.attrelid AND starelid='t'::regclass AND a.attname='a'; -- Justin