Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fCn9j-0007cx-IP for pgsql-performance@arkaria.postgresql.org; Sun, 29 Apr 2018 14:18:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fCn9g-0008OX-7V for pgsql-performance@arkaria.postgresql.org; Sun, 29 Apr 2018 14:18:20 +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 1fCn9f-0008OO-T3 for pgsql-performance@lists.postgresql.org; Sun, 29 Apr 2018 14:18:20 +0000 Received: from mail-io0-x232.google.com ([2607:f8b0:4001:c06::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fCn9b-0005L9-Jc for pgsql-performance@lists.postgresql.org; Sun, 29 Apr 2018 14:18:18 +0000 Received: by mail-io0-x232.google.com with SMTP id f21-v6so7538530iob.13 for ; Sun, 29 Apr 2018 07:18:14 -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:mime-version:content-disposition :in-reply-to:user-agent; bh=+jLJ72ByGlmjbeV+IxYRPnxnkO0XACunsvkXNzOH6Qg=; b=WbQKdm+6XEG6KtxduuENpxoerm3z1hyyJrwxVcpzqz1G4VllKXxNqfEw58C7bJohFQ CFga0F1cnd1NO6DG1k2C4+86jVt1RvMe9n2GQBkDjZTEKmogkrsJkkA4z6spCoV4gdKt YpwGCoUB9Y1D8VWX2uHxRxu58Ly7cyMkfmv+OFjRAFbtx+0VKsOY/UFfssMb+SxWhQ+/ 9fX04SfQxBcCDlSvhcyrKMX564nC5xP6BRW+DNKSTDpRFN7akm468WbwiVcd+vgCoPBG fgMS7geiKaHpqaWUuRDhXXHgWPUMvaI0shrWs5dIRzim8UriAxoYxKsR6W6ul/2x0KsN AKWw== 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:mime-version :content-disposition:in-reply-to:user-agent; bh=+jLJ72ByGlmjbeV+IxYRPnxnkO0XACunsvkXNzOH6Qg=; b=rFVvGc6Gwln3aQ3iP/PSsJzZzA9m7mmiF1sGJdbK67W+Ur3SSxBVLdfTV2AYHRlT8t DLWDallRwwAihKD85wXHIvmpU3E6fm7EhukgH8h+XboLcHhlN6+ZaBXuUVaMB64fpqnf AsD8KxaH05i0hNiARhtDS1tR662x9eoVNODJ162doY+feWU7DxzIkpGILC83X5Wqyowm men2gAI2mb/RFd7u53uN/X0FxfBahOdPvRQMLecgLf59eNU+QtimFx6+ssm0I/A3T7Hl Pw0yOccmtcAv88KPnLr7MqHMr6J08qFnN2+F84XgjlNHvhyu5bod7PQI09Im5aRXhJAI X8Zw== X-Gm-Message-State: ALQs6tBT+5Ru8BbJrghLrDeoS/Gek805dUdY/jTFmCTC16El2Iz2MiSP ZrmIBQrDaRH6Tw/tJBqoMk2sHQ== X-Google-Smtp-Source: AB8JxZpuK4zl/67F7x2BnCT0HgJyqaeFghhaaM9NR5xNWfNsJDrw4290QI2JdjFZcDB7pR29BBatqg== X-Received: by 2002:a6b:88d:: with SMTP id h13-v6mr8945478ioi.43.1525011492772; Sun, 29 Apr 2018 07:18:12 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id q31-v6sm2761796ioi.37.2018.04.29.07.18.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Apr 2018 07:18:12 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 40074804DBA; Sun, 29 Apr 2018 09:18:11 -0500 (CDT) Date: Sun, 29 Apr 2018 09:18:11 -0500 From: Justin Pryzby To: Kaushal Shriyan Cc: pgsql-performance@lists.postgresql.org Subject: Re: Performance issues while running select sql query Message-ID: <20180429141811.GP20071@telsasoft.com> 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 Sun, Apr 29, 2018 at 10:05:23AM +0530, Kaushal Shriyan wrote: > # SELECT serorgid,appname,sum(message_count) AS mtrc0,date_trunc('day', > client_received_start_timestamp at time zone '+5:30:0')::timestamp without > time zone AS time_unit FROM analytics."test.prod.fact" WHERE > client_received_start_timestamp >= '2018-3-28 18:30:0' AND > client_received_start_timestamp < '2018-4-11 18:30:0' AND ((apiproxy in > ('test-service' ) ) and (exchangeinstance != '(not set)' ) and (devemail > != 'test@example.com' ) and (devemail != 'srk@example.com' ) and > (devemail != 'abc@example.com' ) and (devemail != 'xyz@example.com' ) and > (apistatus = 'Success' ) and (apiaction not in > ('LRN','finder','ManuallySelect' ) ) and (appname not in ('Mobile Connect > Developer Portal (Int(', 'MinskHBM', 'LondonHBM', 'SeoulHBM', 'MumbaiHBM', > 'NVirginiaHBM','SPauloHBM', 'Mobile Connect HeartBeat Monitor', > 'PDMAOpenSDKTest1', 'PDMAOpenSDKTest2', 'PDMASDKTest', 'APIHealth', > 'A1qaDemoApp','test', 'dublin o2o test tool', 'Test from John do not > provision' ) ) and (serorgid = 'aircel' )) GROUP BY > serorgid,appname,time_unit ORDER BY time_unit DESC LIMIT 14400 OFFSET 0; This table has inheritence children. Do they have constraints? On what column? Is constraint_exclusion enabled and working for that? It looks like test.prod.fact_624 is being read using index in under 1sec, and the rest using seq scan, taking 5-10sec. So what are the table+index definitions of the parent and childs (say fact_624 and 631). Have the child tables been recently ANALYZE ? Also, have you manually ANALYZE the parent table? On Sun, Apr 29, 2018 at 10:48:48AM +0530, Kaushal Shriyan wrote: > > QUERY PLAN > > Limit (cost=2568002.26..2568038.26 rows=14400 width=35) (actual time=127357.296..127357.543 rows=231 loops=1) > > Buffers: shared hit=28019 read=1954681 ... > > -> Index Scan using "test.prod.fact_624_client_received_start_timestamp_idx" on "test.prod.fact_624" (cost=0.42..10948.27 rows=1002 width=34) (actual time=3.034..278.320 rows=1231 loops=1) > > Index Cond: ((client_received_start_timestamp >= '2018-03-28 18:30:00'::timestamp without time zone) AND (client_received_start_timestamp < '2018-04-11 18:30:00'::timestamp without time zone)) > > Rows Removed by Filter: 42629 > > Buffers: shared hit=27966 read=498 > > -> Seq Scan on "test.prod.fact_631" (cost=0.00..171447.63 rows=16464 width=34) (actual time=0.070..7565.812 rows=20609 loops=1) > > Rows Removed by Filter: 645406 > > Buffers: shared hit=2 read=132279 ...