Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1USvfH-00056z-Ka for pgsql-performance@arkaria.postgresql.org; Thu, 18 Apr 2013 20:42:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1USvfH-0005fu-5L for pgsql-performance@arkaria.postgresql.org; Thu, 18 Apr 2013 20:42:43 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1USVhf-0003Ed-Fs for pgsql-performance@postgresql.org; Wed, 17 Apr 2013 16:59:27 +0000 Received: from mail-ie0-x233.google.com ([2607:f8b0:4001:c03::233]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1USVhc-0003G6-GX for pgsql-performance@postgresql.org; Wed, 17 Apr 2013 16:59:26 +0000 Received: by mail-ie0-f179.google.com with SMTP id 16so2163484iea.38 for ; Wed, 17 Apr 2013 09:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:content-type:subject:message-id:date:to :mime-version:x-mailer; bh=C9zAl+0moeOCS+xEqC/r6k7Z6Ze6/qVuYNEgry6l5Ko=; b=RfhMAO6Z5ipLUT79gSK9SvAkwh7TRDHK5VNx7/+VJ8Xs1OqnxczJz5WnckXs7zifzX yi8kaSLqz0T93nNt2x8m/4DkFWeFtaDKA333kY0vKhFJWO3qvyy6zUlfh+R9BNpYOXuv ndt+3rfKmnp6y9zDj/OC7UbQnLONK6/mTc/RQIkc3GwhZW7LSbnyEkft9yTwlsG+eR8b bQb5Orr81Ut37tWOZs7JCEh1VVeCrApqbs1YC2Z3OhB5EkXMpBi4Z/9j+jzktM55RH9i EC27lL6wBqkunXJVVaSyOniJ28esE0U9tFLRhM/UUQmmS2Onru6jubxUsz7JUtNM+G8S EsmQ== X-Received: by 10.43.148.71 with SMTP id kf7mr3893828icc.42.1366217962828; Wed, 17 Apr 2013 09:59:22 -0700 (PDT) Received: from ?IPv6:2001:470:1f11:7d2:2021:810b:d3ff:29ae? ([2001:470:1f11:7d2:2021:810b:d3ff:29ae]) by mx.google.com with ESMTPS id vb15sm8002635igb.9.2013.04.17.09.59.21 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 17 Apr 2013 09:59:22 -0700 (PDT) From: Michael Okner Content-Type: multipart/alternative; boundary="Apple-Mail=_B108FE47-F972-49D7-BB5E-58981C13AFD2" Subject: Query planner ignoring constraints on partitioned tables when joining Message-Id: <7DF51702-0F6A-4571-80BB-188AAEF260DA@gmail.com> Date: Wed, 17 Apr 2013 11:59:20 -0500 To: pgsql-performance@postgresql.org Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) X-Mailer: Apple Mail (2.1503) X-Pg-Spam-Score: -2.0 (--) 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 --Apple-Mail=_B108FE47-F972-49D7-BB5E-58981C13AFD2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hello all, I'm running into an issue when joining between to tables that are = partitioned by month. At this point I'm leaning towards it being a bug = in the planner but it could be due to something I'm not doing properly = as well. Each parent table is empty and has about 30 child tables, and = there are between 2 and 10 mil rows total in each set of partitions. = When selecting a particular day's data, indexes and constraint exclusion = are used if queried individually and the results return in under a = second. However, querying from the two tables inner/natural joined = together with a single day in the where clause results in a full = sequential scan on the second table, so the query takes a ridiculous = amount of time. Changing the order of the tables in the join changes = which table is fully scanned. All child tables have been recently vacuum analyzed. I've played around = with this every which way, and not been able to get the planner to make = a more reasonable decision. I have several different boxes with varying = physical specs running either CentOS 5.8 or 6.4, and Postgres 8.4.17, = and they all exhibit the same behavior, so I've ruled out the = possibility that it's related to a particular quirk in one database. I = didn't notice the issue at first because the tables weren't large enough = for it to cause any serious performance issues. Now that the tables have = grown, queries involving a join no longer finish in any reasonable = number of hours. I've been able to reproduce the issue in a generic environment and = posted the code to create this environment on my GitHub at = https://github.com/mikeokner/pgsql_test. The query plans demonstrating = this issue are pasted here: http://bpaste.net/show/92138/. I've poked = around on IRC and no one seems to think this is normal behavior. Is it = in fact a bug or is there something I should be doing to fix this = behavior? Regards, Mike= --Apple-Mail=_B108FE47-F972-49D7-BB5E-58981C13AFD2 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Hello all,

I'm running into an issue when = joining between to tables that are partitioned by month. At this point = I'm leaning towards it being a bug in the planner but it could be due to = something I'm not doing properly as well. Each parent table is empty and = has about 30 child tables, and there are between 2 and 10 mil rows total = in each set of partitions. When selecting a particular day's data, = indexes and constraint exclusion are used if queried individually and = the results return in under a second. However, querying from the two = tables inner/natural joined together with a single day in the where = clause results in a full sequential scan on the second table, so the = query takes a ridiculous amount of time. Changing the order of the = tables in the join changes which table is fully = scanned.

All child tables have been recently = vacuum analyzed. I've played around with this every which way, and not = been able to get the planner to make a more reasonable decision. I have = several different boxes with varying physical specs running either = CentOS 5.8 or 6.4, and Postgres 8.4.17, and they all exhibit the same = behavior, so I've ruled out the possibility that it's related to a = particular quirk in one database. I didn't notice the issue at first = because the tables weren't large enough for it to cause any serious = performance issues. Now that the tables have grown, queries involving a = join no longer finish in any reasonable number of = hours.

I've been able to reproduce the issue in = a generic environment and posted the code to create this environment on = my GitHub at https://github.com/mikeok= ner/pgsql_test. The query plans demonstrating this issue are pasted = here: http://bpaste.net/show/92138/. = I've poked around on IRC and no one seems to think this is normal = behavior. Is it in fact a bug or is there something I should be doing to = fix this = behavior?

Regards,
Mike
--Apple-Mail=_B108FE47-F972-49D7-BB5E-58981C13AFD2--