Changes between Initial Version and Version 1 of Ticket #3739


Ignore:
Timestamp:
Apr 16, 2017, 9:23:08 PM (7 years ago)
Author:
robe
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #3739 – Description

    initial v1  
    44
    55Versions:
     6
     7{{{
    68"POSTGIS="2.3.2 r15302" GEOS="3.6.1-CAPI-1.10.1 r4317" PROJ="Rel. 4.9.1, 04 March 2015" GDAL="GDAL 2.1.3, released 2017/20/01 GDAL_DATA not found" LIBXML="2.7.8" LIBJSON="0.12" (core procs from "2.3.0 r15146" need upgrade) RASTER (raster procs from "2.3.0 r (...)"
    79"PostgreSQL 9.6.1, compiled by Visual C++ build 1800, 64-bit"
     10}}}
     11
    812
    913This happens on a full planet_osm_polygon table.
    1014Definition:
     15
     16{{{
    1117CREATE TABLE public.planet_osm_polygon
    1218(
     
    2935  USING btree
    3036  (osm_id);
     37}}}
    3138
    3239I've done an analyze planet_osm_polygon but still the query planner surprises me.
    3340
     41
     42{{{
    3443select s.way from planet_osm_polygon s
    3544join planet_osm_polygon ap on (ST_Within(s.way,ap.way))
    3645where ap.osm_id=123456
    3746
     47}}}
     48
    3849results in a pkey lookup followed by a bitmap index scan
     50
     51{{{
    3952Nested Loop  (cost=6339.51..360823.14 rows=88540 width=229)
    4053  Output: s.way
     
    4861        ->  Bitmap Index Scan on planet_osm_polygon_index  (cost=0.00..6316.81 rows=265621 width=0)
    4962              Index Cond: (ap.way ~ s.way)
     63}}}
     64
    5065
    5166adding ap.way ~ s.way and to the join condition:
     67
     68
     69{{{
    5270select s.way from planet_osm_polygon s
    5371join planet_osm_polygon ap on (ap.way ~ s.way and ST_Within(s.way,ap.way))
    5472where ap.osm_id=123456
     73}}}
     74
    5575
    5676results in a pkey lookup and a normal index-scan
     77
     78
     79{{{
    5780Nested Loop  (cost=1.12..373.05 rows=89 width=229)
    5881  Output: s.way
     
    6588        Filter: _st_contains(ap.way, s.way)
    6689
     90}}}
     91
    6792One thing stands out here: the duplicate index condition ap.way ~ s.way
    6893
    6994My question is: why isn't it planning to use the normal index-scan without adding ap.way ~ s.way.
    7095After all, it is part of the st_within definition:
     96
     97
     98{{{
    7199CREATE OR REPLACE FUNCTION public.st_within(
    72100    geom1 geometry,
     
    76104  LANGUAGE sql IMMUTABLE
    77105  COST 100;
     106
     107}}}