substituting access method gist for obsolete method rtree

1 minute read

背景

PostgreSQL曾经用过的rtree索引访问方法,2005年时经被gist 替代。

http://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=2a8d3d83efeafe7f5d7ba2e56d165f2cc78a7d56

R-tree is dead ... long live GiST.  
author	Tom Lane <tgl@sss.pgh.pa.us>	  
Mon, 7 Nov 2005 17:36:47 +0000 (17:36 +0000)  
committer	Tom Lane <tgl@sss.pgh.pa.us>	  
Mon, 7 Nov 2005 17:36:47 +0000 (17:36 +0000)  
commit	2a8d3d83efeafe7f5d7ba2e56d165f2cc78a7d56  
tree	cf3bf0349a55d4daf51d454cc8bcac9ec8c80ec5	tree | snapshot  
parent	645adf5de8e1f1a829df92a9b80fa0ebbd121942	commit | diff  
R-tree is dead ... long live GiST.  

为了兼容以前的语法(CREATE INDEX xxx on table USING rtree (columns);)

PostgreSQL的策略如下,建立rtree索引时,自动转换为gist。

src/backend/commands/indexcmds.c

	/*  
         * look up the access method, verify it can handle the requested features  
         */  
        accessMethodName = stmt->accessMethod;  
        tuple = SearchSysCache1(AMNAME, PointerGetDatum(accessMethodName));  
        if (!HeapTupleIsValid(tuple))  
        {  
                /*  
                 * Hack to provide more-or-less-transparent updating of old RTREE  
                 * indexes to GiST: if RTREE is requested and not found, use GIST.  
                 */  
                if (strcmp(accessMethodName, "rtree") == 0)  
                {  
                        ereport(NOTICE,  
                                        (errmsg("substituting access method \"gist\" for obsolete method \"rtree\"")));  
                        accessMethodName = "gist";  
                        tuple = SearchSysCache1(AMNAME, PointerGetDatum(accessMethodName));  
                }  
  
                if (!HeapTupleIsValid(tuple))  
                        ereport(ERROR,  
                                        (errcode(ERRCODE_UNDEFINED_OBJECT),  
                                         errmsg("access method \"%s\" does not exist",  
                                                        accessMethodName)));  
        }  

例子:

postgres=# create table t(id int4range);  
CREATE TABLE  
postgres=# create index idx_t_1 on t using rtree(id);  
NOTICE:  substituting access method "gist" for obsolete method "rtree"  
CREATE INDEX  
postgres=# \d+ t  
                            Table "public.t"  
 Column |   Type    | Modifiers | Storage  | Stats target | Description   
--------+-----------+-----------+----------+--------------+-------------  
 id     | int4range |           | extended |              |   
Indexes:  
    "idx_t_1" gist (id)  

参考

1. src/backend/commands/indexcmds.c

Flag Counter

digoal’s 大量PostgreSQL文章入口