Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZnD5Z-0002T5-9i for pgsql-performance@arkaria.postgresql.org; Fri, 16 Oct 2015 22:03:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZnD5Y-000186-Je for pgsql-performance@arkaria.postgresql.org; Fri, 16 Oct 2015 22:03:00 +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) (envelope-from ) id 1ZnD5X-000172-Vd for pgsql-performance@postgresql.org; Fri, 16 Oct 2015 22:03:00 +0000 Received: from mail-lf0-f46.google.com ([209.85.215.46]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZnD5V-0005P1-3n for pgsql-performance@postgresql.org; Fri, 16 Oct 2015 22:02:59 +0000 Received: by lffv3 with SMTP id v3so85945001lff.0 for ; Fri, 16 Oct 2015 15:02:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-type:content-transfer-encoding; bh=3F0dSzNs+VgWWFVLs8FUNOArOXMDh5RQyaRbb12ttxg=; b=V/1htMnyJ5IpjHPI1lFA9Vw7G02Dmq9N1LCN6434vCFFc/zv7s/Bcx1+Mu031BFKeZ tSGsZngpXU8AqitFGMPuDnDQ0hboIv65mm/Pts9LygRv5PLq7s8T2mCFtzDSUatqDE51 cbb4QQM+2zPbUPOJ7x13cncSNSrwlrHe/U0LbYBhOUaj+tV6jcEiJQNuYAXh7px2tPig vP+em64E0aeVajJWO3DbKyq9slPhvp0fDoAiORtkD2qWAt3wg2fiG1UA8/Maf4SvCkZI EhktVYhu00DBm7+bZ1bA9jjG6M2f5TnwymnHNqVNEf8b5EEGjp/IOHECpyS+bVCLymXA 7g8Q== X-Gm-Message-State: ALoCoQl9xroXIBVxOseat9MH8qgyg8Iain9/Eq0JUV5RMOVNRJD08WFEDdJIFSlMR0FZEjNXd13+ X-Received: by 10.25.20.97 with SMTP id k94mr6062219lfi.27.1445032975714; Fri, 16 Oct 2015 15:02:55 -0700 (PDT) Received: from [192.168.1.2] ([46.72.33.152]) by smtp.googlemail.com with ESMTPSA id eu2sm3159140lbc.6.2015.10.16.15.02.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Oct 2015 15:02:55 -0700 (PDT) To: pgsql-performance@postgresql.org From: Vladimir Yavoskiy Subject: query partitioned table is very slow Message-ID: <5621740E.3010002@krevedko.su> Date: Sat, 17 Oct 2015 01:02:54 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 I have about 900 partitioned tables with 67 millons rows. And I found that my query takes too much time! ------------------------------------------------------------------------------ explain ( ANALYZE,VERBOSE,BUFFERS ) select report_id from cars."all" WHERE report_datetime = '2015-10-14 00:02:02+03'::timestamptz AND report_uuid = 'f6b08f92-0d5d-28b0-81c3-0c20c4ca3038'::uuid ------------------------------------------------------------------------------ Append (cost=0.00..4.43 rows=2 width=4) (actual time=0.023..0.023 rows=1 loops=1) Buffers: shared hit=4 -> Seq Scan on cars.all (cost=0.00..0.00 rows=1 width=4) (actual time=0.002..0.002 rows=0 loops=1) Output: all.report_id Filter: ((all.report_datetime = '2015-10-14 00:02:02+03'::timestamp with time zone) AND (all.report_uuid = 'f6b08f92-0d5d-28b0-81c3-0c20c4ca3038'::uuid)) -> Index Scan using day_151014_uuid_idx on cars.day_151014 (cost=0.42..4.43 rows=1 width=4) (actual time=0.020..0.020 rows=1 loops=1) Output: day_151014.report_id Index Cond: (day_151014.report_uuid = 'f6b08f92-0d5d-28b0-81c3-0c20c4ca3038'::uuid) Filter: (day_151014.report_datetime = '2015-10-14 00:02:02+03'::timestamp with time zone) Buffers: shared hit=4 Total runtime: 0.096 ms ------------------------------------------------------------------------------ This query takes about 500ms. But query from only part-table takes 12ms: select report_id from cars.day_151014 WHERE report_datetime = '2015-10-14 00:02:02+03'::timestamptz AND report_uuid = 'f6b08f92-0d5d-28b0-81c3-0c20c4ca3038'::uuid ------------------------------------------------------------------------------ explain ( ANALYZE,VERBOSE,BUFFERS ) select report_id from cars.day_151014 WHERE report_datetime = '2015-10-14 00:02:02+03'::timestamptz AND report_uuid = 'f6b08f92-0d5d-28b0-81c3-0c20c4ca3038'::uuid ------------------------------------------------------------------------------ Index Scan using day_151014_uuid_idx on cars.day_151014 (cost=0.42..4.43 rows=1 width=4) (actual time=0.022..0.023 rows=1 loops=1) Output: report_id Index Cond: (day_151014.report_uuid = 'f6b08f92-0d5d-28b0-81c3-0c20c4ca3038'::uuid) Filter: (day_151014.report_datetime = '2015-10-14 00:02:02+03'::timestamp with time zone) Buffers: shared hit=4 Total runtime: 0.045 ms ------------------------------------------------------------------------------ Query plans seems fine, but why actual query is so slow? p.s. PostgreSQL 9.3.9 x86_64 on Oracle Linux Server release 6.6 (3.8.13-68.3.2.el6uek.x86_64) -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance