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 1f0pqU-0006J6-H8 for pgsql-performance@arkaria.postgresql.org; Tue, 27 Mar 2018 14:45:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f0pqT-0006hW-Jw for pgsql-performance@arkaria.postgresql.org; Tue, 27 Mar 2018 14:45:05 +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 1f0pon-0001s6-Sm for pgsql-performance@lists.postgresql.org; Tue, 27 Mar 2018 14:43:22 +0000 Received: from mail-io0-x231.google.com ([2607:f8b0:4001:c06::231]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f0poj-00083S-WA for pgsql-performance@lists.postgresql.org; Tue, 27 Mar 2018 14:43:20 +0000 Received: by mail-io0-x231.google.com with SMTP id r18so27874047ioa.1 for ; Tue, 27 Mar 2018 07:43:17 -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=U04Ge7WVZfjUPdwDTO2fpbYOLBgTf8CYoAXhNzF2ReU=; b=ewItUfxAoO7+2DOqroim6cSj6oaBFgctfqNcdsx/c3NEstorSCF4FCXxKzgSUUF7oH ew/anNe4gSAfdK4UijO/y6x/XfeuaOD21MydajiKshgVV5GWSW1X4AF74vSCHC5L9LXc +3vRrGSr0j1ilpP3NdZjSmdtruWhUCbUfIqDIa4ZDRO0QpRUeXHjLg+0bUWX4tkCj9Wp sBuZRnkbTraea3llLr5HJPt0LIBkiPVNBbeMCfzBRTZdhve1dcy50lEalBukR0dMf5vk jn4yd6iZWtdYwSs2WYV7IC7F0DGYNpKFUYvaHJ1fqqkRSVR8BMisF6t9XcM87slM9AAF ssQQ== 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=U04Ge7WVZfjUPdwDTO2fpbYOLBgTf8CYoAXhNzF2ReU=; b=TPrVhaQqhPvBwGRV/8iRLsl+LsoJMfQtz3/Gt8IilCC5VTPN/cdsnNej1VIne3U8fx IF5Y+7ilpT8Fnf8nhfCiGxu0lPXJuhrcgij5yvWZ+Pf1CimrUAIbrSURU+741aiY7CFs KJ3MS7JvXZ2ZdUOYWLTDYgZEZ5tmYz8oFK7ZTdeSRu1hI2NuGWrSLLCA+N3aCnRUyWF0 8Vsk+UDru25xKV9VgV/beOzbAW82Nv/UVSWUUV+bTLPzBOPLtwJnDuiD4KMSjBqD0Zwt H9xY8Ls62zmCvLcNjtpA5Hdg7QHRQLCF4PcV0Eh4bRK1ooGXBSjBqkLKZZnOBLBkvjqo ilJA== X-Gm-Message-State: AElRT7FQxSwiHe34qwkcfqvxUoEl+162JygQIc6mJK93yeMUSXIEAuu5 6pNWYWiOLBKO1Hr13RAphNkQNQ== X-Google-Smtp-Source: AIpwx4+dPaRB5ol3IgFRe+0bd/NdRKOYTU2jGWKg97FAM4X8x7cLSsUVvSzsOA8rPXIqfpJ154gmng== X-Received: by 10.107.132.75 with SMTP id g72mr18445126iod.134.1522161797101; Tue, 27 Mar 2018 07:43:17 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id g35sm1088321ioj.9.2018.03.27.07.43.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 07:43:16 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 3637B80140B; Tue, 27 Mar 2018 09:43:15 -0500 (CDT) Date: Tue, 27 Mar 2018 09:43:15 -0500 From: Justin Pryzby To: Glenn Pierce Cc: pgsql-performance@lists.postgresql.org Subject: Re: Slow query on partitioned table. Message-ID: <20180327144315.GO28454@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 Tue, Mar 27, 2018 at 03:14:30PM +0100, Glenn Pierce wrote: > Hi I am having terrible trouble with a simple partitioned table. > Select queries are very slow. .... > The child tables are all like > Check constraints: > "sensor_values_2018q1_timestamp_check" CHECK (ts >= '2018-01-01 > 00:00:00+00'::timestamp with time zone AND ts < '2018-04-01 > 01:00:00+01'::timestamp with time zone) > EXPLAIN (ANALYZE, BUFFERS) SELECT ts::timestamptz, s1.sensor_id, s1.value > FROM sensor_values s1 > WHERE s1.sensor_id = > ANY(ARRAY[596304,597992,610978,597998]) > AND s1.ts >= '2000-01-01 > 00:01:01'::timestamptz AND > s1.ts < '2018-03-20 > 00:01:01'::timestamptz > Shows the following output > https://explain.depesz.com/s/c8HU It's scanning all partitions, so apparently constraint_exclusion isn't working. Is it because the CHECK has ts with different timezones +00 and +01 ?? Also, it looks funny to use 00:01:01 as the beginning of the day (although I think it's true that an HR department would understand that better..). Justin