Skip to content
Snippets Groups Projects
Select Git revision
  • benchmark-tools
  • postgres-lambda
  • master default
  • REL9_4_25
  • REL9_5_20
  • REL9_6_16
  • REL_10_11
  • REL_11_6
  • REL_12_1
  • REL_12_0
  • REL_12_RC1
  • REL_12_BETA4
  • REL9_4_24
  • REL9_5_19
  • REL9_6_15
  • REL_10_10
  • REL_11_5
  • REL_12_BETA3
  • REL9_4_23
  • REL9_5_18
  • REL9_6_14
  • REL_10_9
  • REL_11_4
23 results

rtree_gist.sql.in

Blame
    • Tom Lane's avatar
      f933766b
      Restructure pg_opclass, pg_amop, and pg_amproc per previous discussions in · f933766b
      Tom Lane authored
      pgsql-hackers.  pg_opclass now has a row for each opclass supported by each
      index AM, not a row for each opclass name.  This allows pg_opclass to show
      directly whether an AM supports an opclass, and furthermore makes it possible
      to store additional information about an opclass that might be AM-dependent.
      pg_opclass and pg_amop now store "lossy" and "haskeytype" information that we
      previously expected the user to remember to provide in CREATE INDEX commands.
      Lossiness is no longer an index-level property, but is associated with the
      use of a particular operator in a particular index opclass.
      
      Along the way, IndexSupportInitialize now uses the syscaches to retrieve
      pg_amop and pg_amproc entries.  I find this reduces backend launch time by
      about ten percent, at the cost of a couple more special cases in catcache.c's
      IndexScanOK.
      
      Initial work by Oleg Bartunov and Teodor Sigaev, further hacking by Tom Lane.
      
      initdb forced.
      f933766b
      History
      Restructure pg_opclass, pg_amop, and pg_amproc per previous discussions in
      Tom Lane authored
      pgsql-hackers.  pg_opclass now has a row for each opclass supported by each
      index AM, not a row for each opclass name.  This allows pg_opclass to show
      directly whether an AM supports an opclass, and furthermore makes it possible
      to store additional information about an opclass that might be AM-dependent.
      pg_opclass and pg_amop now store "lossy" and "haskeytype" information that we
      previously expected the user to remember to provide in CREATE INDEX commands.
      Lossiness is no longer an index-level property, but is associated with the
      use of a particular operator in a particular index opclass.
      
      Along the way, IndexSupportInitialize now uses the syscaches to retrieve
      pg_amop and pg_amproc entries.  I find this reduces backend launch time by
      about ten percent, at the cost of a couple more special cases in catcache.c's
      IndexScanOK.
      
      Initial work by Oleg Bartunov and Teodor Sigaev, further hacking by Tom Lane.
      
      initdb forced.
    rtree_gist.sql.in 11.09 KiB
    begin transaction;
    --
    --
    --
    -- BOX ops
    --
    --
    --
    -- define the GiST support methods
    create function gbox_consistent(opaque,box,int4) returns bool as 'MODULE_PATHNAME' language 'C';
    
    create function gbox_compress(opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
    
    create function rtree_decompress(opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
    
    create function gbox_penalty(opaque,opaque,opaque) returns opaque as 'MODULE_PATHNAME' language 'C' with (isstrict);
    
    create function gbox_picksplit(opaque, opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
    
    create function gbox_union(bytea, opaque) returns box as 'MODULE_PATHNAME' language 'C';
    
    create function gbox_same(box, box, opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
    
    -- add a new opclass (non-default)
    INSERT INTO pg_opclass (opcamid, opcname, opcintype, opcdefault, opckeytype)
        VALUES (
            (SELECT oid FROM pg_am WHERE amname = 'gist'),
            'gist_box_ops',
            (SELECT oid FROM pg_type WHERE typname = 'box'),
            false,
            0);
    
    -- get the comparators for boxes and store them in a tmp table
    SELECT o.oid AS opoid, o.oprname
    INTO TEMP TABLE rt_ops_tmp
    FROM pg_operator o, pg_type t
    WHERE o.oprleft = t.oid 
       and t.typname = 'box';
    
    -- using the tmp table, generate the amop entries 
    -- box_left
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) 
       SELECT opcl.oid, 1, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops' 
          and c.oprname = '<<';
    
    -- box_overleft
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) 
       SELECT opcl.oid, 2, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops' 
          and c.oprname = '&<';
    
    -- box_overlap
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) 
       SELECT opcl.oid, 3, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops' 
          and c.oprname = '&&';
    
    -- box_overright
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) 
       SELECT opcl.oid, 4, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops' 
          and c.oprname = '&>';
    
    -- box_right
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
       SELECT opcl.oid, 5, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops' 
          and c.oprname = '>>';
    
    -- box_same
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) 
       SELECT opcl.oid, 6, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops' 
          and c.oprname = '~=';
    
    -- box_contains
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
       SELECT opcl.oid, 7, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops' 
          and c.oprname = '~';
    
    -- box_contained
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
       SELECT opcl.oid, 8, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops' 
          and c.oprname = '@';
    
    DROP table rt_ops_tmp;
    
    -- add the entries to amproc for the support methods
    -- note the amprocnum numbers associated with each are specific!
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 1, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops'
          and proname = 'gbox_consistent';
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 2, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops'
          and proname = 'gbox_union';
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 3, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops'
          and proname = 'gbox_compress';
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 4, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops'
          and proname = 'rtree_decompress';
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 5, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops'
          and proname = 'gbox_penalty';
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 6, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops'
          and proname = 'gbox_picksplit';
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 7, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_box_ops'
          and proname = 'gbox_same';
    
    --
    --
    --
    -- POLYGON ops
    --
    --
    --
    -- define the GiST support methods
    create function gpoly_consistent(opaque,polygon,int4) returns bool as 'MODULE_PATHNAME' language 'C';
    
    create function gpoly_compress(opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
    
    create function gpoly_penalty(opaque,opaque,opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
    
    create function gpoly_picksplit(opaque, opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
    
    create function gpoly_union(bytea, opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
    
    create function gpoly_same(opaque, opaque, opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
    
    -- add a new opclass (non-default)
    INSERT INTO pg_opclass (opcamid, opcname, opcintype, opcdefault, opckeytype)
        VALUES (
            (SELECT oid FROM pg_am WHERE amname = 'gist'),
            'gist_poly_ops',
            (SELECT oid FROM pg_type WHERE typname = 'polygon'),
            false,
            0);
    
    -- get the comparators for polygons and store them in a tmp table
    -- hack for 757 (poly_contain_pt) Teodor
    SELECT o.oid AS opoid, o.oprname
    INTO TEMP TABLE rt_ops_tmp
    FROM pg_operator o, pg_type t
    WHERE o.oprleft = t.oid and o.oid <> 757
       and t.typname = 'polygon';
    
    -- using the tmp table, generate the amop entries 
    -- poly_left
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) 
       SELECT opcl.oid, 1, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops' 
          and c.oprname = '<<';
    
    -- poly_overleft
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) 
       SELECT opcl.oid, 2, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops' 
          and c.oprname = '&<';
    
    -- poly_overlap
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) 
       SELECT opcl.oid, 3, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops' 
          and c.oprname = '&&';
    
    -- poly_overright
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) 
       SELECT opcl.oid, 4, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops' 
          and c.oprname = '&>';
    
    -- poly_right
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
       SELECT opcl.oid, 5, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops' 
          and c.oprname = '>>';
    
    -- poly_same
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) 
       SELECT opcl.oid, 6, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops' 
          and c.oprname = '~=';
    
    -- poly_contains
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
       SELECT opcl.oid, 7, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops' 
          and c.oprname = '~';
    
    -- poly_contained
    INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
       SELECT opcl.oid, 8, false, c.opoid
       FROM pg_opclass opcl, rt_ops_tmp c
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops' 
          and c.oprname = '@';
    
    DROP table rt_ops_tmp;
    
    -- add the entries to amproc for the support methods
    -- note the amprocnum numbers associated with each are specific!
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 1, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops'
          and proname = 'gpoly_consistent';
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 2, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops'
          and proname = 'gpoly_union';
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 3, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops'
          and proname = 'gpoly_compress';
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 4, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops'
          and proname = 'rtree_decompress';
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 5, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops'
          and proname = 'gpoly_penalty';
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 6, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops'
          and proname = 'gpoly_picksplit';
    
    INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
       SELECT opcl.oid, 7, pro.oid
       FROM pg_opclass opcl, pg_proc pro
       WHERE
          opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
          and opcname = 'gist_poly_ops'
          and proname = 'gpoly_same';
    
    end transaction;