�������� ������������ �������

GiST home | Introduction | GiST interface (Russian) | Readings
Search PostgreSQL resources | OpenFTS | PostgreSQL site

����������:

����� ��������� � ���������� �������� �������� � ����� ������ GiST programming tutorial

����� ���������

��������� �������� GiST ����� ��������� � ������� ������ �������.

GiST ������������� ������������� ����� ����� ������ �������� ������ ��� ������ � ����: SEARCH, INSERT, DELETE. ��������� ����� �������� ����� � ������� 7 ������������ �������, ������� ����������� ������ ���������������.

����������� ������� ���������� �������� � �������, ������������� � ��������� ���������:

typedef struct GISTENTRY
{
        Datum           key;     /* ���������� ���� */
        Relation        rel;     /* ������ */ 
        Page            page;    /* �������� ������� */
        OffsetNumber    offset;  /* ��������� � ������� */
        int             bytes;   /* ����� ����� � ������, ����� ���� ������ -1  */
        bool            leafkey; /* �������, �����������, ��� � key ��������� ��
				 ����, � �������� �� ������� */
} GISTENTRY;

����� ���������:
  1. �� ���� �� ������������ ������� �� ����� ����� ������� NULL
  2. ���� ��������, ����� penalty(�� ��������), ������� �� ���������� NULL ��� GISTENTRY � ��������� key NULL.

������������ �������

1.
GISTENTRY *   compress( GISTENTRY * in ) 
GISTENTRY * decompress( GISTENTRY * in )
��� ������� �������� �� ����������/������������ ������. ���� ������� ������ �������� ����� (key), ��:
  1. ��� ������ ���������� ������ palloc'������� �������� ��� ��������� ��� � �����( � ������ pass-by-reference ���� �����).
  2. ����������� � ����� ��������� �������� rel, page, offset, leafkey.
  3. ��������� ���������� bytes.
  4. ������ ��������� (in) �� �������, � �� ������ pfree �� in �� in->key

��� ������ compress in->leafkey ���������� � true ���� �������� � key ����� �� �������, � �� �� �������. � ���� ������, ���� ���� �� �������� ����, ����������� ���� ���������� bytes � ���������� leafkey=FALSE.

� ������ ���� compress/decompress �� ������ �������� ������, �� ��� ����� ��������� ��������� �������:

  GISTENTRY *   compress( GISTENTRY * in ){
	return in;
  }
���� ��������� ������������ �������� ����� ���������� ������ ����� ��������� ����� ������� decompress.

2.

bool equal( Datum a, Datum b);
���������� TRUE ������ � ������ a=b.

3.

float * penalty( GISTENTRY *origentry, GISTENTRY *newentry, float *result)
��������� ���� ���������� origentry->key ��� ��� ����������� � newentry->key. ����������� �������� ������ ��������� � *result � ������� ��������� �� ����.

���� ��� ������� �� �������� ��� isstrict, �� key ����� ���� NULL. ����� ������� �� ���������� � ���������, ��� ���� = 0 ���� ���� �� ���� �� ���������� is NULL

4.

Datum union(bytea *entryvec, int *size)
��������� ����������� ������. ���������� ������������ ���� (�� GISTENTRY!). � *size �������� ������ ��������������� ����� � ������.
entryvec - ��� ��������� �� ������ GISTENTRY.
  int len = (VARSIZE(entryvec) - VARHDRSZ)/sizeof(GISTENTRY); - ������ �������
  GISTENTRY arr = (GISTENTRY *) VARDATA(entryvec); - ���������� ��������� �� ������ 
������ ������� �� �������� NULL ���������.

5.

bool consistent( Datum key, Datum query, StrategyNumber strategy )
��������� ���� (key) �� ������������ ������� (query) ��������� � ������� strategy � ���������� TRUE � ������ ������������, ����� FALSE

���� ���� ��������� �� ���������� �������� ������, ������� ������ ���������� TRUE ���� key ����� ��������������� query (FALSE ���� key ����� �� ������������� query).

������� ��������: ���� ���� ��������� �� �������� (leaf) ��������, �� ��� ������������ ���������� RECHECK ��� ���������� �������� (��. CREATE OPERATOR CLASS). RECHECK - ������ ������� ������ �����, ��� - �����.

������ GIST_LEAF(key) ���������� TRUE ���� ���� ��������� �� leaf ��������.

������, ����� �������� ����� strategy ������������� ����� � ������� ���������� SQL( �� ������� gist_box_ops, ��������� ������ ������ ����������� ):

  select
        pg_amop.amopstrategy,
        pg_operator.oprname,
        pg_amop.amopreqcheck
  from
        pg_type,
        pg_operator,
        pg_opclass,
        pg_am,
        pg_amop
  where
        pg_type.typname = 'box' and
        pg_am.amname = 'gist' and
        pg_opclass.opcname = 'gist_box_ops' and
	pg_am.oid=pg_opclass.opcamid and
        pg_opclass.oid = pg_amop.amopclaid and
        pg_opclass.opcintype = pg_type.oid and
        pg_amop.amopopr = pg_operator.oid;
��������������, ��� �������� ������ opclass �/��� �������� ���� ������������ �� ���������� ��������� ������.

6.

GIST_SPLITVEC * split(bytea *entryvec, GIST_SPLITVEC *v)
��������� ������ ������ entryvec �� ���. ������ entryvec �� ����� ��������� NULL ��������

��������� GIST_SPLITVEC:

  typedef struct GIST_SPLITVEC
  {
        OffsetNumber *spl_left;         /* array of entries that go left */
        int           spl_nleft;        /* size of this array */
        Datum         spl_ldatum;       /* Union of keys in spl_left */
        OffsetNumber *spl_right;        /* array of entries that go right */
        int           spl_nright;       /* size of the array */
        Datum         spl_rdatum;       /* Union of keys in spl_right */
	...        
  } GIST_SPLITVEC;
��������� �������� ������ ���������� �����, ��� ������� �����, �� ��������� ���� �� ������ �� ���������.

v->spl_left & v->spl_right ������ �������������� ��������������, ��� �������� ��� ������ ��������� ������ ��������� ������� entryvec (���� ����� �� ����� ����������� � spl_left � spl_right ������������). �������� � ������� entryvec ���������� � 1, � �� � 0!! ����� ������� ������� ������������ spl_ldatum & spl_rdatum.

����������� ������������ ������� ( version 7.2)

������ ��� ������ 7.3 ������ ����

� �������� ������� ���������� ���������� R-tree ��� ���� box.

����������� ������������ ������� (version 7.3)