Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qwIHz-00AuJp-NK for pgsql-general@arkaria.postgresql.org; Fri, 27 Oct 2023 08:33:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qwIHy-00DU0j-DJ for pgsql-general@arkaria.postgresql.org; Fri, 27 Oct 2023 08:33:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qwIHx-00DU0b-Ry for pgsql-general@lists.postgresql.org; Fri, 27 Oct 2023 08:33:54 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qwIHv-0034UM-3N for pgsql-general@lists.postgresql.org; Fri, 27 Oct 2023 08:33:53 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-9a6190af24aso285330466b.0 for ; Fri, 27 Oct 2023 01:33:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20230601.gappssmtp.com; s=20230601; t=1698395629; x=1699000429; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=8xIaZ5RGGFSgB3vLslWI9l3lq6PbWm3Boq4TaJ3oEDo=; b=kgMV2TRWzMUSQ/whagRKL0uIjFzvPrkuIFxbrqa87bFi7eMgjD5fex1xKDUfJtJjcI p3Mv6FNM5k6FSYzoPeSNRHKPmT81Cgp/f2E6DYqTnq/uUlNpuw8UFe3QkTSmcwcJVmKH EKNou3t3hvfELVrvOMABY6X2pPE6bvG0rQJJ2bddQPd+PBl3UhwYF3wQZVm3Lh/Mtwyh 1PaGxT0FJIw/Dx5FdvnQa5Wlag1Ja0d5Mgy9ApBHpnaSJJpdnQS4Vmi7lEfT8eM6WezE rUYmL2DVmaSvnxseAeHDNlnSGt3RB31wMfPetGZKpHA7DP9fzUpxM/T66q4dw5Lodk58 eW1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698395629; x=1699000429; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8xIaZ5RGGFSgB3vLslWI9l3lq6PbWm3Boq4TaJ3oEDo=; b=qCiMA3/fMyUqMqyUmWQnKdv6Vm9YfWbtc5Ei57ZpfHHH52aePjqZWrPyPthvwiuf5l tmGoCKsPz/dyR8EANCgQVgZcS7eTYNEEpLWccbVmg+N0apAF4hE/n5+fK2XwX4vihxVw kgvQ5bluebzQp/MAPHgom6bEpf1g9QIdWVbSIo/wMcLSDjGOK9EFlBbpeb01PKOQ6luX tpET/oLKIacYbvIuP35YrF96vH4lmECn7o/s3Chlex3sZWSIGd3vvNma9lJDaSWROm9g S26kLCSt7edXAewqwyuhFM3ajXiYjHZXamt1U1lcCocKedm0BrDgurh6WCnUXspWIzNQ g8hA== X-Gm-Message-State: AOJu0YxKDjf5gKYe5Uq0g022G4hO72bwlLI+HzjTOfC262j8fPl/DGEM lLmsD7x6MUe30Vlad9oHQ175xLyZaaGcwm3d9QA= X-Google-Smtp-Source: AGHT+IHDPq//TDTXm2plhnpbZGrrzfUbhXC3b2L0aqpNnAKNS39EClD3dWvLFPq/Vi1p2CmhLK45Hg== X-Received: by 2002:a17:907:9286:b0:9be:68db:b763 with SMTP id bw6-20020a170907928600b009be68dbb763mr1612383ejc.71.1698395629514; Fri, 27 Oct 2023 01:33:49 -0700 (PDT) Received: from localhost.localdomain ([2001:871:5e:9ed1:f603:606a:d25e:a194]) by smtp.gmail.com with ESMTPSA id a13-20020a170906190d00b009ae3d711fd9sm835689eje.69.2023.10.27.01.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:33:49 -0700 (PDT) Message-ID: <0ce0470f4727ea3f5253999640f3fdc633459c33.camel@cybertec.at> Subject: Re: Correct way of using complex expressions as partitioning key From: Laurenz Albe To: Alexander Rumyantsev , pgsql-general@lists.postgresql.org Date: Fri, 27 Oct 2023 10:33:48 +0200 In-Reply-To: <20D8B5BB-DB0B-400D-8560-2F5765361CB1@rumyantsev.com> References: <20D8B5BB-DB0B-400D-8560-2F5765361CB1@rumyantsev.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2023-10-27 at 07:27 +0300, Alexander Rumyantsev wrote: > Is there some correct way to use complex expressions as a key for partiti= oned table? > Inserting works as expected, but select runs over all partitions until us= e complete > partition key expression as predicate >=20 > test=3D# create table test ( > id text, > v1 bigint, > v2 bigint > ) > partition by range (((v1 + v2) % 10)); > CREATE TABLE >=20 > test=3D# explain analyze select * from test where v1 =3D 100 and v2 =3D 1= 00; > [no partition pruning] >=20 > test=3D# explain analyze select * from test where ((v1 + v2) % 10) =3D 0 = and v1 =3D 100 and v2 =3D 100; > [partition pruning] Yes, you only get partition pruning if the WHERE clause contains a comparis= on with the partitioning key. There is no way around that. Yours, Laurenz Albe