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 1fQzq7-0004Se-HW for pgsql-general@arkaria.postgresql.org; Thu, 07 Jun 2018 18:40:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fQzq5-0005ZZ-TW for pgsql-general@arkaria.postgresql.org; Thu, 07 Jun 2018 18:40:49 +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.89) (envelope-from ) id 1fQzq5-0005ZP-LT for pgsql-general@lists.postgresql.org; Thu, 07 Jun 2018 18:40:49 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fQzq2-00075g-BA for pgsql-general@postgresql.org; Thu, 07 Jun 2018 18:40:49 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 3305421CBE; Thu, 7 Jun 2018 14:40:45 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 07 Jun 2018 14:40:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=JJE8YETPJY42TMsD+2gvk8lp6nC/r xeViyNbuJLVjsU=; b=y1yyAWUDxpDGKdAjJF9jdIjfpBlILkxArjXrlY43Fz0zs 4RGptz3WHi4SMm27lchC50CbtzdIN3QCbBw0lxM4JdfI358Kr3iDiddmMXMXNUBK FlbVqfCH5eztwIc64Bgb9s+64XdYWeOlUZFx7HgwpmWZuiNscKlmPcjI+l2NhTE6 B07ForelAG5a1giygsEzzoisn4M34UZsraI181Q+AVe2FiZCgtjnGqEuSEi1KPP9 GhIHx2+KUjpD2YMJyZq4pm+BClcVIsBryDl3rb6ynSJNWGfkNndPW2v8pr1x7k+m Fg5sx6F4DcjS3jAE5pO0+IVH4nV5qiAYVD5bjxUfg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=JJE8YE TPJY42TMsD+2gvk8lp6nC/rxeViyNbuJLVjsU=; b=b8vCD+sYBYCzVfnqRmj9MV YY5beMoja/eKkBgf2X+aUJc1Z/dmGpTMMczDeE2vngsPEsDffDzd17AD1LSEG/10 85/MjXTo1a2mEgnltNdJv/f0lSTgfeJ0xNIuSDIB19cNm6/wGs+AuvtoZDQ+6ZWV s5l/7OCLdjLXZZKcm4Bk1/B2sK7yTRd9BCEql2BQ31mdfsXtJOO4lu6u5dZvEvnY Xy8Vu0jtO6wS14e7J3sH/Qnxo7vpbtVOQ91f0AI2TB7RiQpFAtN9z2BARpRZaMDp 9yZ1PxpfNKna1ejEy/3cXNmPPNUe4TAeAP6QfIiJyZjpPNJhfs1ukwBpL4EdcAUA == X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.159.209]) by mail.messagingengine.com (Postfix) with ESMTPA id 1C7B210260; Thu, 7 Jun 2018 14:40:44 -0400 (EDT) Subject: Re: Query hitting empty tables taking 48 minutes To: Robert Creager , pgsql-general@postgresql.org Cc: Robert Creager References: <186A2F70-5953-4FE4-9586-BF3F114AF1CC@logicalchaos.org> From: Adrian Klaver Message-ID: Date: Thu, 7 Jun 2018 11:40:39 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <186A2F70-5953-4FE4-9586-BF3F114AF1CC@logicalchaos.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 06/07/2018 11:17 AM, Robert Creager wrote: > > I have a system running FreeBSD 11.1-STABLE, PostgreSQL 9.6.8,Java > OpenJDK 1.8.0_131, jdbc 9.3-1104-jdbc41 which is exhibiting very bizarre > behavior.  A query is executing against a couple of tables that have 1 > and 0 records in them.  ds3.job_entry has 0 rows, ds3.blob has 1 row. >  If I execute the query manually via command line, it executes fine. >  There are no other active queries, no locks.  The system is idle, in > our Dev Test group, so I can leave it this way for a bit of time.  The > general software setup is in production and I’ve seen nothing like this > before.  Even a system with 300M ds3.blob entries executes this query fine. So I am assuming the problem query is being run through Java/jdbc, correct? There is also the below in the log: " ... execute fetch from S_2037436/C_2037437 ..." My guess is that we will need to see the Java code that sets up and runs the query. Is that possible? > > Jun  7 17:24:21 blackpearl postgres[10670]: [7737-1] > db=tapesystem,user=Administrator,app=[unknown],client=127.0.0.1 > LOG:  duration: *2903612.206* ms  execute fetch > from S_2037436/C_2037437: SELECT * FROM ds3.blob WHERE EXISTS (SELECT * > FROM ds3.job_entry WHERE blob_id = ds3.blob.id AND > (job_id = $1)) > > tapesystem=# explain analyze SELECT * FROM ds3.blob WHERE EXISTS (SELECT > * FROM ds3.job_entry WHERE blob_id = ds3.blob.id > AND (job_id = 'b51357cd-e07a-4c87-a50b-999c347a5c71')); >                                                               QUERY PLAN > --------------------------------------------------------------------------------------------------------------------------------------- > >  Nested Loop  (cost=0.84..6.89 rows=1 width=77) (actual > time=0.044..0.044 rows=0 loops=1) >    ->  Index Scan using job_entry_job_id_idx on > job_entry  (cost=0.42..2.44 rows=1 width=16) (actual time=0.042..0.042 > rows=0 loops=1) >          Index Cond: (job_id = > 'b51357cd-e07a-4c87-a50b-999c347a5c71'::uuid) >    ->  Index Scan using blob_pkey on blob  (cost=0.42..4.44 rows=1 > width=77) (never executed) >          Index Cond: (id = job_entry.blob_id) >  Planning time: 0.388 ms >  Execution time: 0.118 ms > > > pid client_port runtime query_start datname state query usename > 10670 11211 0 years 0 mons 0 days 0 hours 43 mins 28.852273 secs > 2018-06-07 17:24:22.026384 tapesystem active SELECT * FROM ds3.blob > WHERE EXISTS (SELECT * FROM ds3.job_entry WHERE blob_id = ds3.blob.id > AND (job_id = $1)) Administrator > > > > From the system with 300M ds3.blob entries, which works fine (along > with every other system in house): > > QUERY PLAN > Nested Loop  (cost=0.57..738052.90 rows=164379 width=75) (actual > time=1.001..1947.029 rows=50000 loops=1) >   ->  Seq Scan on job_entry  (cost=0.00..10039.50 rows=164379 width=16) > (actual time=0.871..56.442 rows=50000 loops=1) >         Filter: (job_id = 'ef27d2fa-2727-424e-8f44-da9e33a5ca05'::uuid) >         Rows Removed by Filter: 60001 >   ->  Index Scan using blob_pkey on blob  (cost=0.57..4.42 rows=1 > width=75) (actual time=0.037..0.037 rows=1 loops=50000) >         Index Cond: (id = job_entry.blob_id) > Planning time: 6.330 ms > Execution time: 1951.564 ms > > > Please keep my CC of my work e-mail present. > > Best, > Robert -- Adrian Klaver adrian.klaver@aklaver.com