Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g39Wr-0000Mk-Uc for pgsql-performance@arkaria.postgresql.org; Fri, 21 Sep 2018 00:42:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g39Wp-0002va-Qi for pgsql-performance@arkaria.postgresql.org; Fri, 21 Sep 2018 00:42:39 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g39Wp-0002vR-C7 for pgsql-performance@lists.postgresql.org; Fri, 21 Sep 2018 00:42:39 +0000 Received: from mail-io1-xd2b.google.com ([2607:f8b0:4864:20::d2b]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g39Wl-0007nq-7X for pgsql-performance@lists.postgresql.org; Fri, 21 Sep 2018 00:42:38 +0000 Received: by mail-io1-xd2b.google.com with SMTP id h16-v6so166638ioj.1 for ; Thu, 20 Sep 2018 17:42:34 -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:in-reply-to:user-agent; bh=PXKR18n2LC/y5TWMGUmakUUI4n+Q3Oaz469m2msBCIg=; b=iLJJ6liY/aOssaNvq31CMPOGcQmqTpICCPHkYKAuKns2EtpUhO2idfFxMpI1OIHKxk is2bIPk7O80dkDuZUW5PfFUmf15g2cV5x7s5JIjCFbTpJpn1Aux/92ClLWotkTSKaCK4 dIOjZMrW6lFEad3f9RRxcpvSkAJaffX7cYQzwP8fK/B15E9g7zuaH55Sub3cSDnDVr4p TIaTKvpGUzSJNZ+D8FUGnxc1sNciATZkn6TjWYvTQoO0cJkgmFGyraHCuh2WNcBRUTPT wd1cufUTeBczePZUchesslENMW51ltrj4LlCEXFf0Gio0s2Y7KlH5Z5R5MiTJcxDTSOV oRxg== 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:in-reply-to:user-agent; bh=PXKR18n2LC/y5TWMGUmakUUI4n+Q3Oaz469m2msBCIg=; b=LkA6EP9qNoYKmsBU+IjUxBEbwGeneXuJXP5ulAPz46BfnphRQUBROWcfHpwkgdh0BO n+L32wKQREEY0zpGLsooRL+0HX7KtdYDQhOCLSuttqnYxUAKA6tZKVzzW2GNdnrqeZhi uk7wn9RhMVGz7V3wmzTrGNIxxK2OmwdOkE+ezSuNK0Xu/rT83mP4ayCFgIiZukNdoxnR jFu0cFfMvgIhMaCAnTo274IeW6IP+jswQhgTVksvkHPfNgI8TM/4pYl6xQGgqpqC+9EQ NQW2gpZWL+XEve00XdDONk6KEjbebmN4GaImYO2VvK0MFX1qsGT8pfWpKUI4D9T/scWf fCDA== X-Gm-Message-State: APzg51CaX4pmjIogvj2X1rFQkbvzHlxTjYdO8FsJ+8HSFy9hfCxn7ooe 2E/pw4Fbdvw54+1sckfEri4VLA== X-Google-Smtp-Source: ANB0VdYOTcZJAk0Wbk2gRoB93w9JRhzJUvZeGxqxW9YlaOUNFOaqGSBc/r0JUpkLGjKufdRxCVeApQ== X-Received: by 2002:a6b:9651:: with SMTP id y78-v6mr36159459iod.283.1537490554022; Thu, 20 Sep 2018 17:42:34 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 185-v6sm1780377itk.28.2018.09.20.17.42.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 17:42:33 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id CC7DD8025FB; Thu, 20 Sep 2018 19:42:32 -0500 (CDT) Date: Thu, 20 Sep 2018 19:42:32 -0500 From: Justin Pryzby To: Vladimir Ryabtsev Cc: pgsql-performance@lists.postgresql.org Subject: Re: Why could different data in a table be processed with different performance? Message-ID: <20180921004232.GC2471@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Sep 20, 2018 at 05:07:21PM -0700, Vladimir Ryabtsev wrote: > I am experiencing a strange performance problem when accessing JSONB > content by primary key. > I noticed that with some IDs it works pretty fast while with other it is > 4-5 times slower. It is suitable to note, there are two main 'categories' > of IDs in this table: first is range 270000000-500000000, and second is > range 10000000000-100030000000. For the first range it is 'fast' and for > the second it is 'slow'. Was the data populated differently, too ? Has the table been reindexed (or pg_repack'ed) since loading (or vacuumed for that matter) ? Were the tests run when the DB was otherwise idle? You can see the index scan itself takes an additional 11sec, the "heap" portion takes the remaining, additional 14sec (33s-12s-7s). So it seems to me like the index itself is slow to scan. *And*, the heap referenced by the index is slow to scan, probably due to being referenced by the index less consecutively. > "Small' range: disk read rate is around 10-11 MB/s uniformly across the > test. Output rate was 1300-1700 rows/s. Read ratio is around 13% (why? > Shouldn't it be ~ 100% after drop_caches?). I guess you mean buffers cache hit ratio: read/hit, which I think should actually be read/(hit+read). It's because a given buffer can be requested multiple times. For example, if an index page is read which references multiple items on the same heap page, each heap access is counted separately. If the index is freshly built, that'd happen nearly every item. Justin > Aggregate (cost=8635.91..8635.92 rows=1 width=16) (actual time=6625.993..6625.995 rows=1 loops=1) > Buffers: shared hit=26847 read=3914 > -> Index Scan using articles_pkey on articles (cost=0.57..8573.35 rows=5005 width=107) (actual time=21.649..1128.004 rows=5000 loops=1) > Index Cond: ((article_id >= 438000000) AND (article_id <= 438005000)) > Buffers: shared hit=4342 read=671 > Aggregate (cost=5533.02..5533.03 rows=1 width=16) (actual time=33219.100..33219.102 rows=1 loops=1) > Buffers: shared hit=6568 read=7104 > -> Index Scan using articles_pkey on articles (cost=0.57..5492.96 rows=3205 width=107) (actual time=22.167..12082.624 rows=2416 loops=1) > Index Cond: ((article_id >= '100021000000'::bigint) AND (article_id <= '100021010000'::bigint)) > Buffers: shared hit=50 read=2378