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 1fR0Jt-0006PN-H1 for pgsql-general@arkaria.postgresql.org; Thu, 07 Jun 2018 19:11:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fR0Jr-0001Fs-Bg for pgsql-general@arkaria.postgresql.org; Thu, 07 Jun 2018 19:11:35 +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 1fR0Jr-0001Fj-0r for pgsql-general@lists.postgresql.org; Thu, 07 Jun 2018 19:11:35 +0000 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fR0Jj-0007lr-8q for pgsql-general@lists.postgresql.org; Thu, 07 Jun 2018 19:11:34 +0000 Received: by mail-pf0-x242.google.com with SMTP id j20-v6so5360093pff.10 for ; Thu, 07 Jun 2018 12:11:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=IhZnRfFxjUKWpNYuo48EPDKIopTyshF4MS6PwgZ9noI=; b=ICRTsUXUDYihfe1d8X7RGYNFjcMYxlEH1wTdSbA4rYzNvxAMS07B/ZvEm9RmhmEu35 RW5JgTmViBNE6XWZM2FkyhpsDCvpKu/JoThuTHb6Sp8RM1aBnVVNrhtUdH6e1GgEOtjl f0QXf/zaU44iY2xBbgLjqnL0SdfAMcb/B8qeXVfL8dVs7pT74aclZMSPMJNJ6kwUmHo9 G6q9XZ6JSL9QeYcbVNR5CFEq37FJV/PhXMtb2Q2thXW8ttWmSCzNJ9McHsoVrFmG9BPU S6AG6Z4JQmg1sBF6eUqo0PhU4yJ6OR3Z/2gGBvaY1Fdalzd4wANtbTrH8W4SoGFspQ9w A6Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=IhZnRfFxjUKWpNYuo48EPDKIopTyshF4MS6PwgZ9noI=; b=Fi/aCcO9TG3fG6PHN/Nz2+SS62ghNtviTq0sZwyuupbIhAdGXw1yDQ0J0SNO2gBbMm 94l+7s3VxVKHpQCygH8rJjjU+hqYPRDgPL3sOB4Hd8rZVSo2Lv2lSldwcVKKHeGUMnpw vt6VewoPIF+CJ0M5tS14JbjJbtZOCIdEMODYGYGjPaREaNiFjjgwnEMm+gth98GSf5E6 CSzn3VhNFfJ2KPcBODK3mDUqydDcbvGxU9BIFl0PxoO4FXtHIwrHue8yqwePcq7Tz9Fw oSyJsuPM7exstANHUbWcIEz3UXDoq+WBc7y97+uSaAVTKvW8jKNFfMf7kzJV0JqFjXJb BSIQ== X-Gm-Message-State: APt69E3yvrXcHQubpdAngLHJs5m4Q7SNI6/IjBXB/ugNdSXacITIFQvH hDcVdjvg/8sdif3JHj0UJf2B1e/z X-Google-Smtp-Source: ADUXVKKfGDXIxaYFq7okPund4Fooy2/kRa/XKMWxhBx2cO+Ma2JmR5SUPusV8uDP7zOM4ns/FmXNMg== X-Received: by 2002:a63:2f04:: with SMTP id v4-v6mr2568217pgv.33.1528398683818; Thu, 07 Jun 2018 12:11:23 -0700 (PDT) Received: from [10.104.134.14] ([155.100.47.6]) by smtp.gmail.com with ESMTPSA id u13-v6sm24472805pfh.147.2018.06.07.12.11.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 12:11:23 -0700 (PDT) Subject: Re: Query hitting empty tables taking 48 minutes To: pgsql-general@lists.postgresql.org References: <186A2F70-5953-4FE4-9586-BF3F114AF1CC@logicalchaos.org> From: Rob Sargent Message-ID: <3f0ce0f4-1103-bce8-7398-c77c7ef8c739@gmail.com> Date: Thu, 7 Jun 2018 13:11:21 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------5193121D85BC4D8E5F5E979B" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------5193121D85BC4D8E5F5E979B Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 06/07/2018 12:55 PM, Robert Creager wrote: > > >> On Jun 7, 2018, at 12:40 PM, Adrian Klaver > > wrote: >> >> 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? > > Yes. > >> >> There is also the below in the log: >> >> " ... execute fetch from S_2037436/C_2037437 …" > > So, that means nothing to me.  Something to you? > >> >> My guess is that we will need to see the Java code that sets up and >> runs the query. Is that possible? > > OMG, you had to ask ;-)  Not really, for two reasons.  It’s an actual > shipping product, and I’d have to send you so much code to get from > the source of the query down through the execute…. Now, the execute, > on it’s own, is below.  m_statement is a java.sql.PreparedStatement. >  Keep in mind this code is literally executing millions of times a day > on a busy system.  Except for this special snowflake system... > > private Executor executeQuery() > { >     final MonitoredWork monitoredWork = new MonitoredWork( > StackTraceLogging.NONE, m_readableSql.getLogMessagePreExecution() ); >     try >     { >         m_closeTransactionUponClose = ( null == m_transactionNumber ); >         m_statement.setFetchSize( 10000 ); >         final Duration duration = new Duration(); >         m_resultSet = m_statement.executeQuery(); >         m_readableSql.log( duration, null ); >         return this; >     } >     catch ( final SQLException ex ) >     { >         throw new DaoException( >                 "Failed to execute: > " + m_readableSql.getLogMessagePreExecution(), >                 ex ); >     } >     finally >     { >         monitoredWork.completed(); >     } > } > >> >>> 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 >>> pidclient_portruntimequery_startdatnamestatequeryusename >>> 10670112110 years 0 mons 0 days 0 hours 43 mins 28.852273 secs >>> 2018-06-07 17:24:22.026384tapesystemactiveSELECT * 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 > What's the url doing in "blob_id = ds3.blob.id



On 06/07/2018 12:55 PM, Robert Creager wrote:


On Jun 7, 2018, at 12:40 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:

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?

Yes.


There is also the below in the log:

" ... execute fetch from S_2037436/C_2037437 …"

So, that means nothing to me.  Something to you?


My guess is that we will need to see the Java code that sets up and runs the query. Is that possible?

OMG, you had to ask ;-)  Not really, for two reasons.  It’s an actual shipping product, and I’d have to send you so much code to get from the source of the query down through the execute…. Now, the execute, on it’s own, is below.  m_statement is a java.sql.PreparedStatement.  Keep in mind this code is literally executing millions of times a day on a busy system.  Except for this special snowflake system...

private Executor executeQuery()
{
    final MonitoredWork monitoredWork = new MonitoredWork( 
            StackTraceLogging.NONE, m_readableSql.getLogMessagePreExecution() );
    try
    {
        m_closeTransactionUponClose = ( null == m_transactionNumber );
        m_statement.setFetchSize( 10000 );
        final Duration duration = new Duration();
        m_resultSet = m_statement.executeQuery();
        m_readableSql.log( duration, null );
        return this;
    }
    catch ( final SQLException ex )
    {
        throw new DaoException( 
                "Failed to execute: " + m_readableSql.getLogMessagePreExecution(),
                ex );
    }
    finally
    {
        monitoredWork.completed();
    }
}


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 <http://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 <http://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 <http://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

What's the url doing in "blob_id = ds3.blob.id <http://ds3.blob.id"?
--------------5193121D85BC4D8E5F5E979B--