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 1ljv3i-0000KC-Qw for pgsql-performance@arkaria.postgresql.org; Fri, 21 May 2021 02:38:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ljv3h-0003hE-Qv for pgsql-performance@arkaria.postgresql.org; Fri, 21 May 2021 02:38:41 +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 1ljv3h-0003h4-Ex for pgsql-performance@lists.postgresql.org; Fri, 21 May 2021 02:38:41 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ljv3e-0000DA-V7 for pgsql-performance@postgresql.org; Fri, 21 May 2021 02:38:40 +0000 Received: by mail-ot1-x331.google.com with SMTP id u25-20020a0568302319b02902ac3d54c25eso16776913ote.1 for ; Thu, 20 May 2021 19:38:38 -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:content-transfer-encoding:in-reply-to :user-agent; bh=u8x7nDfLh/NZk0AYv/HplPB8o5jdtXLz/T1l8Zsia3I=; b=xbKucWQBId3DMMh9oFu4yAV/ssn+hVDM27xfe7A13Mt6m+jGGKcm5M4/tU5AQydzH8 U+wJ8kCcKFzKOxI1IoOirCTPitfdNtA7ZFpY0c37V2wiI4zmQrd7Xkb3a9PJm6v12T5h y06u0bSCKC1r7TdCeWfr0F8vNP6lGV5mf308IaBZN/cfgIYwhoBlYTNJ7Y4YQvARZzwn miieLoXocGHErpDed5DCCCsaOp6KHjIo7HHbmAp5lZhmGhr/I3SVJb13vT8ND93dLWrc zwyJWHlmkCxfGEXX/iQtGaS6xljh3hGg+sgLeuhnn9PJoiwEEi5yb4PFgh4+HZP6p1x7 oAqQ== 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:content-transfer-encoding :in-reply-to:user-agent; bh=u8x7nDfLh/NZk0AYv/HplPB8o5jdtXLz/T1l8Zsia3I=; b=Zz2mvZkNahriH20k3h7PIScBhW44vnzcgtCYLrHTFUwUurldYpwgHWSBygJ/XQmWi0 MsAoJLpJbdadXeonzX4cWISeUEmXnWXnxQSu17jQgfBM5gbpKxTKlYrqbokR2wIJQxD2 XVZL/4TAQwuMqK/v/s7Pb9qmm8x6N9ZAQA+7JyajQW/tEsqMuw7yW1/LmjgN/TSXTkfk IQ5fTopINzgpIQAmvINZ0h/s6UuvJ2/EYslmXVOwy/P6oaX0VBEucMp1mJAjimXGmdme bb1UAfwboPE1KSIrNQq5HaQnWDVO30/2OpBB/oGdn88rHP0QdnbxZOyCoh7yjIanj++T uDzg== X-Gm-Message-State: AOAM531iSQ8YY2mVDvyHnCFvZ9LAwQsOzmLcvz5NNHK2YHWhRprENeHl pdLGdEQlYlPuVdxAhdErfUrw3g== X-Google-Smtp-Source: ABdhPJza9UpRhGOGS3SvxJMzNWU++eC3rjxQOQm4A651aXsG0IpIxDBHcHb2M9p3giMAwvo05vK0gw== X-Received: by 2002:a9d:63d3:: with SMTP id e19mr6099025otl.64.1621564718081; Thu, 20 May 2021 19:38:38 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id a71sm949310oib.20.2021.05.20.19.38.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 May 2021 19:38:37 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 7C377800B17; Thu, 20 May 2021 21:38:36 -0500 (CDT) Date: Thu, 20 May 2021 21:38:36 -0500 From: Justin Pryzby To: Nagaraj Raj Cc: David Rowley , Pgsql-performance Subject: Re: Partition with check constraint with "like" Message-ID: <20210521023836.GH3676@telsasoft.com> References: <87840670.92362.1621557131080.ref@mail.yahoo.com> <87840670.92362.1621557131080@mail.yahoo.com> <1347719485.144821.1621564574978@mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1347719485.144821.1621564574978@mail.yahoo.com> 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 Fri, May 21, 2021 at 02:36:14AM +0000, Nagaraj Raj wrote: > Thank you. This is a great help.  > But "a" have some records with alpha and numeric.  So then you should make one or more partitions FROM ('1')TO('9'). > example : > insert into mytable values('alpha'),('bravo'); > insert into mytable values('1lpha'),('2ravo'); > > > On Thursday, May 20, 2021, 06:23:14 PM PDT, David Rowley wrote: > > On Fri, 21 May 2021 at 12:32, Nagaraj Raj wrote: > > I am trying to create partitions on the table based on first letter of the column record  value using inherit relation & check constraint. > > You'll get much better performance out of native partitioning than you > will with the old inheritance method of doing it. > > >  EXECUTE 'CREATE TABLE partition_tab.' || c_table || '(check ( name like '''|| chk_cond||''')) INHERITS (' ||TG_TABLE_NAME|| ');'; > > This is a bad idea. There's a lock upgrade hazard here that could end > up causing deadlocks on INSERT.  You should just create all the tables > you need beforehand. > > I'd recommend you do this using RANGE partitioning. For example: > > create table mytable (a text not null) partition by range (a); > create table mytable_a partition of mytable for values from ('a') to > ('b'); -- note the upper bound of the range is non-inclusive. > create table mytable_b partition of mytable for values from ('b') to ('c'); > insert into mytable values('alpha'),('bravo'); > > explain select * from mytable where a = 'alpha'; >                             QUERY PLAN > ------------------------------------------------------------------- > Seq Scan on mytable_a mytable  (cost=0.00..27.00 rows=7 width=32) >   Filter: (a = 'alpha'::text) > (2 rows) > > The mytable_b is not scanned.