Postgresql

如何在 Postgresql 中增加索引行的最大大小?

  • August 6, 2019

我想使用此處建議的解決方案對 512 維向量執行 KNN 。

  1. 我無法使用 512 維立方體數組創建表。通過更改CUBE_MAX_DIM原始碼中的來解決。
  2. 無法在尺寸 > 200 的表上創建索引。設置block_size=32。現在與dimensionality<=510.
  3. 更改block_size並嘗試使用 512-d 向量在表上創建索引後出現新錯誤ERROR: index row requires 8208 bytes, maximum size is 8191

是否可以增加此限制?

這將需要進行重大更改,我懷疑這是否可以輕鬆完成。

請參閱以下摘錄src/include/access/itup.h

/*
* Index tuple header structure
*
* All index tuples start with IndexTupleData.  If the HasNulls bit is set,
* this is followed by an IndexAttributeBitMapData.  The index attribute
* values follow, beginning at a MAXALIGN boundary.
*
* Note that the space allocated for the bitmap does not vary with the number
* of attributes; that is because we don't have room to store the number of
* attributes in the header.  Given the MAXALIGN constraint there's no space
* savings to be had anyway, for usual values of INDEX_MAX_KEYS.
*/

typedef struct IndexTupleData
{
   ItemPointerData t_tid;      /* reference TID to heap tuple */

   /* ---------------
    * t_info is laid out in the following fashion:
    *
    * 15th (high) bit: has nulls
    * 14th bit: has var-width attributes
    * 13th bit: AM-defined meaning
    * 12-0 bit: size of tuple
    * ---------------
    */

   unsigned short t_info;      /* various info about tuple */

} IndexTupleData;               /* MORE DATA FOLLOWS AT END OF STRUCT */
[...]

/*
* t_info manipulation macros
*/
#define INDEX_SIZE_MASK 0x1FFF
#define INDEX_AM_RESERVED_BIT 0x2000    /* reserved for index-AM specific
                                        * usage */
#define INDEX_VAR_MASK  0x4000
#define INDEX_NULL_MASK 0x8000

您要達到的限制是INDEX_SIZE_MASK,要增加它,您必須更改元組標頭,使其t_info具有兩個以上的字節。

也許就這麼簡單,但它可能會對程式碼的其他部分產生影響。

引用自:https://dba.stackexchange.com/questions/244624