Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X9FbK-0005gC-PF for pgsql-bugs@arkaria.postgresql.org; Mon, 21 Jul 2014 15:34:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X9FbK-0002Rt-8e for pgsql-bugs@arkaria.postgresql.org; Mon, 21 Jul 2014 15:34:06 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X9FbJ-0002Rn-Cs for pgsql-bugs@postgresql.org; Mon, 21 Jul 2014 15:34:05 +0000 Received: from mail-wi0-x236.google.com ([2a00:1450:400c:c05::236]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1X9FbF-0001On-La for pgsql-bugs@postgresql.org; Mon, 21 Jul 2014 15:34:03 +0000 Received: by mail-wi0-f182.google.com with SMTP id d1so4279422wiv.15 for ; Mon, 21 Jul 2014 08:33:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hasegeli.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=3b0eELGSsIY8SxEEiaYG8H1DW23+kEVptw4ZyMxxKEA=; b=ZDIveGfNYfQAoVuNNrXEjD73ffBnbXczoi36IKPn0hQwO4M5SF2FkI7lMIUAf0jBOD wLulWI9HU1LvhL0FBrGRzXfsYnlGDC5jwvPxx5u5W8rtEwqW89/LdWiTXMrw82jWJ3S0 G53wSLp8DWJWBoA8Ua8giBeBEVrkN6oT3slVg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=3b0eELGSsIY8SxEEiaYG8H1DW23+kEVptw4ZyMxxKEA=; b=kUlamqQi21CSmUd9MMWWXh8Ro3XTji0QmPAwedFDAxPQObk3cY86hCxB2inHZDR0lf dUlYuOulqcSEQYMUh4gXGIuigRnT0wVIAnxdd/tFAsCqSKcoTrxnLmoF0T6zM29Nluri 2UAtKAyAGJgw6PyL9ON6f6d7REDCfHkvI5AquXbcXUhDbra9Vh+JSzuPeXpCF6e22iXL tTRMC+wxldwTj4OBd/2mDx0qOcDmsjdNuyLtUo5JeI+En0xlG23bGiL40xld/ozaFYzc ZUDDYdQswypxjl0x2bUYFqEXdZrOBd4QZRUuFe0RIPyie3cqptjsXBO0xHAgSarj0SK3 DppQ== X-Gm-Message-State: ALoCoQlD0LS0w1MBepcHiVCbdqSEnbJEAE8vN7aKTxFqxlB9dvO+gHLegRzKxSAky+IaKuRwGYQy X-Received: by 10.194.62.167 with SMTP id z7mr23534334wjr.112.1405956836817; Mon, 21 Jul 2014 08:33:56 -0700 (PDT) Received: from hasegeli-2.local ([88.246.70.52]) by mx.google.com with ESMTPSA id rw4sm38387985wjb.44.2014.07.21.08.33.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Jul 2014 08:33:56 -0700 (PDT) Date: Mon, 21 Jul 2014 18:33:49 +0300 From: Emre Hasegeli To: "Burgess, Freddie" Cc: pgsql-bugs@postgresql.org Subject: Re: PostgreSQL 9.3.4 Query Problems Message-ID: <20140721153349.GA66435@hasegeli-2.local> References: <3BBE635F64E28D4C899377A61DAA9FE034EE454B@NBSVR-MAIL01.radiantblue.local> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <3BBE635F64E28D4C899377A61DAA9FE034EE454B@NBSVR-MAIL01.radiantblue.local> User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org > Query planner is not selecting the most efficient index, can anything be done to correct this problem? Trimmed explain outputs: > -> Index Scan using sidx_sponser_report_y2014m06 > Index Cond: (sponser_location && ... > Filter: ((origin_date_time >= ... > Rows Removed by Filter: 3849011 > Total runtime: 63913.610 ms > -- Then I disable the spatial index > -> Index Scan using idx_sessiondatetime_rpi_sponser_report_y2014m06 > Index Cond: ((session_uid = ... > Filter: ((sponser_location && ... > Rows Removed by Filter: 1128161 > Total runtime: 1124.355 ms It looks like a problem caused by selectivity estimation. PostgreSQL will choose the index which will return less rows. The second index actually returns less rows than the first one, but probably PostgreSQL does not know about it. There is more chance that the selectivity estimation function of the && operator misguides the planner. I do not know about PostGIS, but selectivity estimation functions for geometrical data types in the core are just stubs returning constants. So, I would not expect much. Best solution I can think of is to avoid that kind of queries. pgsql-general@, pgsql-performance@ or maybe PostGIS mailing lists seems like a better place to ask for help. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs