Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cC3xy-00033R-DZ for pgsql-performance@arkaria.postgresql.org; Wed, 30 Nov 2016 12:26:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cC3xx-00013l-Te for pgsql-performance@arkaria.postgresql.org; Wed, 30 Nov 2016 12:26:25 +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 1cC3xx-00013e-90 for pgsql-performance@postgresql.org; Wed, 30 Nov 2016 12:26:25 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cC3xs-0003dC-RE for pgsql-performance@postgresql.org; Wed, 30 Nov 2016 12:26:24 +0000 Received: by mail-wm0-x22a.google.com with SMTP id g23so267977638wme.1 for ; Wed, 30 Nov 2016 04:26:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=s24-com.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=H+tI4+LuH8KTx4dnlipJJzWpnsfwnOdiW4ZXV26wD1c=; b=P88kvFQC58J45LCxUk3PqCcWIRLIBK9tOqjakRR82zVkA/KygsXqY5LVIrEfPFwbJY AQ0SGW1RQu0PYhLw2BoWxJeJ17ypqMJLkN7hJKCNPDLgt8yTmAL7hik/vmc+juq1J0Vh YKBIY68waPB/od+UT0wUXTZ6/x+ieI9cbCn/RTdalYKltR8CJ/WNKF2KAxK3gZHWTXIh rPki/gCTSzLNjJsz1Mjv/ItJ9l0Bmob61xcTtq3WY4pGa5AWHUKRAikTuZz3p7aA1xZJ kaDFYlc7nT9t06oFuGyMJB0+fc38tWli2IYtcVhQlvqIxMYBDmTzXeIY4x2AP6Gqp53q aMqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=H+tI4+LuH8KTx4dnlipJJzWpnsfwnOdiW4ZXV26wD1c=; b=KWcdxgZGJ2ImhgrdbVRpIC21ojsI7pPKeD4tHPT9UybMWOo8m0WkF4EfG2hqnF2V4z FSMhXUDMlLCtlTp/04KxfOeLJ55Gzu+X08uhhubQFEMigsSqSBYliPci+6f2V1QhPh24 eSzw1CDBjSZFd5n3W4yZ1zd47Sv5ATTCW7fHEPznVK4xqgpBbpL6+M0gvvQz04YsO00s jvOM9tiw4j9e8kBMCdDNLWB4C3pksnln9XZrc6Ro3Zr7H9ePBuFwsMzUFcYMxxYgQ43o Gz2jFU1jgzFCQ1hPkbXZIuPzuaccA9GMqbKng3YceWUmS8QvWy0KQ9rwY98sdHAgDEtb LlVA== X-Gm-Message-State: AKaTC01JaMLZgzO19LycvtxH/JIVXBuvMxa+crHh+f2FPTuxPSS2SBCORzbQoewtzLkbT7b9 X-Received: by 10.28.57.193 with SMTP id g184mr27366315wma.122.1480508777953; Wed, 30 Nov 2016 04:26:17 -0800 (PST) Received: from [10.90.160.126] ([87.253.171.201]) by smtp.gmail.com with ESMTPSA id jm6sm72778430wjb.27.2016.11.30.04.26.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Nov 2016 04:26:17 -0800 (PST) From: Marc-Olaf Jaschke Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.1 \(3251\)) Subject: performance issue with bitmap index scans on huge amounts of big jsonb documents Message-Id: Date: Wed, 30 Nov 2016 13:26:16 +0100 To: pgsql-performance@postgresql.org X-Mailer: Apple Mail (2.3251) X-Pg-Spam-Score: -2.6 (--) 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 Hi, i have a performance issue with bitmap index scans on huge amounts of big j= sonb documents. =3D=3D=3D=3D=3D Background =3D=3D=3D=3D=3D=20 - table with big jsonb documents - gin index on these documents - queries using index conditions with low selectivity =3D=3D=3D=3D=3D Example =3D=3D=3D=3D=3D=20 select version();=20 > PostgreSQL 9.6.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 2012= 0313 (Red Hat 4.4.7-17), 64-bit show work_mem; > 1GB -- setup test data create table bitmap_scan_test as select i, (select jsonb_agg(jsonb_build_object('x', i % 2, 'filler', md5(j::text))) f= rom generate_series(0, 100) j) big_jsonb from generate_series(0, 100000) i; create index on bitmap_scan_test using gin (big_jsonb); analyze bitmap_scan_test; -- query with bitmap scan explain analyze select count(*) from bitmap_scan_test where big_jsonb @> '[{"x": 1, "filler": "cfcd208495d565ef66e7dff9f98764da"}]'; Aggregate (cost=3D272.74..272.75 rows=3D1 width=3D8) (actual time=3D622.27= 2..622.272 rows=3D1 loops=3D1) -> Bitmap Heap Scan on bitmap_scan_test (cost=3D120.78..272.49 rows=3D1= 00 width=3D0) (actual time=3D16.496..617.431 rows=3D50000 loops=3D1) Recheck Cond: (big_jsonb @> '[{"x": 1, "filler": "cfcd208495d565ef6= 6e7dff9f98764da"}]'::jsonb) Heap Blocks: exact=3D637 -> Bitmap Index Scan on bitmap_scan_test_big_jsonb_idx (cost=3D0.= 00..120.75 rows=3D100 width=3D0) (actual time=3D16.371..16.371 rows=3D50000= loops=3D1) Index Cond: (big_jsonb @> '[{"x": 1, "filler": "cfcd208495d56= 5ef66e7dff9f98764da"}]'::jsonb) Planning time: 0.106 ms Execution time: 622.334 ms perf top -p... shows heavy usage of pglz_decompress: Overhead Shared Object Symbol 51,06% postgres [.] pglz_decompress 7,33% libc-2.12.so [.] memcpy ... =3D=3D=3D=3D=3D End of example =3D=3D=3D=3D=3D=20=20 I wonder why bitmap heap scan adds such a big amount of time on top of the = plain bitmap index scan.=20 It seems to me, that the recheck is active although all blocks are exact [1= ] and that pg is loading the jsonb for the recheck. Is this an expected behavior? Regards, Marc-Olaf [1] (http://dba.stackexchange.com/questions/106264/recheck-cond-line-in-que= ry-plans-with-a-bitmap-index-scan) --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance