Re: Too few rows expected by Planner on partitioned tables

From: Michael Lewis <mlewis(at)entrata(dot)com>
To: Julian Wolf <julian(dot)wolf(at)invenium(dot)io>
Cc: Justin Pryzby <pryzby(at)telsasoft(dot)com>, pgsql-performance Postgres Mailing List <pgsql-performance(at)lists(dot)postgresql(dot)org>
Subject: Re: Too few rows expected by Planner on partitioned tables
Date: 2020-08-26 13:32:41
Message-ID: CAHOFxGpb-CmmNz=R3wy26-Ft08ijRo-n+S6eeBkQM5znaYcfxg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Wed, Aug 26, 2020, 1:37 AM Julian Wolf <julian(dot)wolf(at)invenium(dot)io> wrote:

> Hi Justin,
>
> thank you very much for your help and sorry for the late answer.
>
> After testing around with your suggestions, it actually was the daterange
> type which caused all the problems. Messing around with the statistics
> value improved performance drastically but did not solve the problem. We
> decided to replace the daterange type with a BIGINT and calculate the "id"
> of the daterange by just using the BIGINT (2x 4 bytes) representation of
> the daterange. Thus, it can be transformed in both directions immutably.
>
> CREATE OR REPLACE FUNCTION to_daterange_id(daterange DATERANGE)
> RETURNS BIGINT
> IMMUTABLE
> LANGUAGE plpgsql
> AS
> $$
> BEGIN
> return (extract(EPOCH FROM lower(daterange))::BIGINT << 32) |
> extract(EPOCH FROM upper(daterange))::BIGINT;
> end;
>
> --------------------------------------------------------------------------------------------------------------
> CREATE OR REPLACE FUNCTION to_daterange(daterange_id BIGINT)
> RETURNS DATERANGE
> IMMUTABLE
> LANGUAGE plpgsql
> AS
> $$
> BEGIN
> RETURN daterange(to_timestamp(daterange_id >> 32)::DATE, to_timestamp(daterange_id & x'FFFFFFFF'::BIGINT)::DATE);
> END;
> $$;
>
>
You might want to consider changing that language declaration to SQL.

>

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Nagaraj Raj 2020-09-04 21:18:41 Query performance issue
Previous Message Julian Wolf 2020-08-26 06:54:39 Re: Too few rows expected by Planner on partitioned tables