Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aujP5-0007qC-UD for pgsql-performance@arkaria.postgresql.org; Mon, 25 Apr 2016 16:30:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1aujP5-0004bV-B2 for pgsql-performance@arkaria.postgresql.org; Mon, 25 Apr 2016 16:30:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1aujNP-0002Om-O1 for pgsql-performance@postgresql.org; Mon, 25 Apr 2016 16:28:47 +0000 Received: from mail-lf0-x22c.google.com ([2a00:1450:4010:c07::22c]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1aujNM-0005rZ-Nb for pgsql-performance@postgresql.org; Mon, 25 Apr 2016 16:28:47 +0000 Received: by mail-lf0-x22c.google.com with SMTP id c126so120622096lfb.2 for ; Mon, 25 Apr 2016 09:28:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-transfer-encoding; bh=IxYpmWLSw3+f70BOl6G8zv6Itu066laHS6q1vLto12w=; b=y5GM8fiWxbkw/OLI4D/rrMAeXzbVN1VBuluP+mYaPGYuXunhTRSVff4fbBRQyRhGlK YiJmUX5yz6TYvxTUX922k+EmoefrVVFqRAdC/bB9JTfdTZn50H4e35Xed83VWpNaQq08 HlBpUkQO1PWPNYDsOaXTQM/wHnkR3jwSxTjtgmc5W+u0iwrrG08q9UU5YSA5mRc/oqHI x7Hio6x0uckZaz+BQzQstR9iIPSloNXVOlZDVE/WV0oupSnQ0XoIzKOwC96b4Yy98Atn 9lRR+qyEvuHPF70j7qohTufgE9TYV0950ZQot/wz/qcQ8pQVSnoEbMzCUKYam8HqemZd /YMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-transfer-encoding; bh=IxYpmWLSw3+f70BOl6G8zv6Itu066laHS6q1vLto12w=; b=GVAZxTCSTqAFDuqecK6SpZ27Yxh6NJPHahusoIyMOazNrQPBZylKKQFBQRCbZBmjP6 udsIzw3cIgC5uKW0d4KzjC7Ky1g5ouhXYWtTAoLgZHk5Jt462u+X7AM90aa6Hwwnh68j Bnalkml5qnqP67yesE5FSkuFL2IB0Z/aU2HU7ZyBlIiHb+L41OzWchtgRCHq9aEsM6jw 6hdRwgwi9KfVIaKpR6VTC2q+0v4+4Cy2WVCtOk91uTLCxBVyqEVxT+xlg52KnXqAObRP IVLX6pB70UAneH7YBagNmkVthWZiquB+lglRPWpVw1Mqh9mX86VK9sfX1eHTpWya33MV GmOw== X-Gm-Message-State: AOPr4FU0VUPgFapfP9R2cgAZwcvxbSd6DxttlP18TdRhBeN/HkbYsAz9ReiiA6SjsrnNTZjTgLHbg6fYHDgEHA== MIME-Version: 1.0 X-Received: by 10.25.148.197 with SMTP id w188mr4465434lfd.40.1461601722316; Mon, 25 Apr 2016 09:28:42 -0700 (PDT) Received: by 10.112.205.197 with HTTP; Mon, 25 Apr 2016 09:28:42 -0700 (PDT) In-Reply-To: References: <5717D07E.3070802@sigaev.ru> Date: Mon, 25 Apr 2016 11:28:42 -0500 Message-ID: Subject: Re: Performant queries on table with many boolean columns From: Merlin Moncure To: bricklen Cc: Rob Imig , "pgsql-performance@postgresql.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On Sun, Apr 24, 2016 at 3:14 PM, bricklen wrote: > Query plan for the md5() index test: > > Index Scan using lots_of_columns_md5_idx on lots_of_columns > (cost=3D0.93..3.94 rows=3D1 width=3D208) (actual time=3D0.043..0.043 rows= =3D1 loops=3D1) > Index Cond: ('1ba23a0668ec17e230d98c270d6664dc'::text =3D > md5((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((= (((((((((((((((((((((((((((((((c1)::text > || (c2)::text) || (c3)::text) || (c4)::text) || (c5)::text) || (c6)::text) > || (c7)::text) || (c8)::text) || (c9)::text) || (c10)::text) || (c11)::te= xt) > || (c12)::text) || (c13)::text) || (c14)::text) || (c15)::text) || > (c16)::text) || (c17)::text) || (c18)::text) || (c19)::text) || (c20)::te= xt) > || (c21)::text) || (c22)::text) || (c23)::text) || (c24)::text) || > (c25)::text) || (c26)::text) || (c27)::text) || (c28)::text) || (c29)::te= xt) > || (c30)::text) || (c31)::text) || (c32)::text) || (c33)::text) || > (c34)::text) || (c35)::text) || (c36)::text) || (c37)::text) || (c38)::te= xt) > || (c39)::text) || (c40)::text) || (c41)::text) || (c42)::text) || > (c43)::text) || (c44)::text) || (c45)::text) || (c46)::text) || (c47)::te= xt) > || (c48)::text) || (c49)::text) || (c50)::text) || (c51)::text) || > (c52)::text) || (c53)::text) || (c54)::text) || (c55)::text) || (c56)::te= xt) > || (c57)::text) || (c58)::text) || (c59)::text) || (c60)::text) || > (c61)::text) || (c62)::text) || (c63)::text) || (c64)::text) || (c65)::te= xt) > || (c66)::text) || (c67)::text) || (c68)::text) || (c69)::text) || > (c70)::text) || (c71)::text) || (c72)::text) || (c73)::text) || (c74)::te= xt) > || (c75)::text) || (c76)::text) || (c77)::text) || (c78)::text) || > (c79)::text) || (c80)::text) || (c81)::text) || (c82)::text) || (c83)::te= xt) > || (c84)::text) || (c85)::text) || (c86)::text) || (c87)::text) || > (c88)::text) || (c89)::text) || (c90)::text) || (c91)::text) || (c92)::te= xt) > || (c93)::text) || (c94)::text) || (c95)::text) || (c96)::text) || > (c97)::text) || (c98)::text) || (c99)::text) || (c100)::text))) > Buffers: shared hit=3D4 > Planning time: 0.389 ms > Execution time: 0.129 ms > (5 rows) Hm. Maybe use VARBIT? (assuming there are no null values or null can be treated as false). CREATE OR REPLACE FUNCTION MakeVarBit(VARIADIC BOOL[]) RETURNS VARBIT AS $$ SELECT string_agg(CASE WHEN v THEN '1' ELSE '0' END, '')::VARBIT FROM ( SELECT UNNEST($1) v ) q; $$ LANGUAGE SQL IMMUTABLE; postgres=3D# select MakeVarBit(true, true, false); makevarbit =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80 110 create index on lots_of_columns (MakeVarBit(c1, c2, c3, c4 ...)); merlin --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance