您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“PostgreSQL中BufTableInsert函數(shù)有什么作用”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
BufferDesc
共享緩沖區(qū)的共享描述符(狀態(tài))數(shù)據(jù)
/* * Flags for buffer descriptors * buffer描述器標(biāo)記 * * Note: TAG_VALID essentially means that there is a buffer hashtable * entry associated with the buffer's tag. * 注意:TAG_VALID本質(zhì)上意味著有一個(gè)與緩沖區(qū)的標(biāo)記相關(guān)聯(lián)的緩沖區(qū)散列表?xiàng)l目。 */ //buffer header鎖定 #define BM_LOCKED (1U << 22) /* buffer header is locked */ //數(shù)據(jù)需要寫入(標(biāo)記為DIRTY) #define BM_DIRTY (1U << 23) /* data needs writing */ //數(shù)據(jù)是有效的 #define BM_VALID (1U << 24) /* data is valid */ //已分配buffer tag #define BM_TAG_VALID (1U << 25) /* tag is assigned */ //正在R/W #define BM_IO_IN_PROGRESS (1U << 26) /* read or write in progress */ //上一個(gè)I/O出現(xiàn)錯(cuò)誤 #define BM_IO_ERROR (1U << 27) /* previous I/O failed */ //開始寫則變DIRTY #define BM_JUST_DIRTIED (1U << 28) /* dirtied since write started */ //存在等待sole pin的其他進(jìn)程 #define BM_PIN_COUNT_WAITER (1U << 29) /* have waiter for sole pin */ //checkpoint發(fā)生,必須刷到磁盤上 #define BM_CHECKPOINT_NEEDED (1U << 30) /* must write for checkpoint */ //持久化buffer(不是unlogged或者初始化fork) #define BM_PERMANENT (1U << 31) /* permanent buffer (not unlogged, * or init fork) */ /* * BufferDesc -- shared descriptor/state data for a single shared buffer. * BufferDesc -- 共享緩沖區(qū)的共享描述符(狀態(tài))數(shù)據(jù) * * Note: Buffer header lock (BM_LOCKED flag) must be held to examine or change * the tag, state or wait_backend_pid fields. In general, buffer header lock * is a spinlock which is combined with flags, refcount and usagecount into * single atomic variable. This layout allow us to do some operations in a * single atomic operation, without actually acquiring and releasing spinlock; * for instance, increase or decrease refcount. buf_id field never changes * after initialization, so does not need locking. freeNext is protected by * the buffer_strategy_lock not buffer header lock. The LWLock can take care * of itself. The buffer header lock is *not* used to control access to the * data in the buffer! * 注意:必須持有Buffer header鎖(BM_LOCKED標(biāo)記)才能檢查或修改tag/state/wait_backend_pid字段. * 通常來(lái)說(shuō),buffer header lock是spinlock,它與標(biāo)記位/參考計(jì)數(shù)/使用計(jì)數(shù)組合到單個(gè)原子變量中. * 這個(gè)布局設(shè)計(jì)允許我們執(zhí)行原子操作,而不需要實(shí)際獲得或者釋放spinlock(比如,增加或者減少參考計(jì)數(shù)). * buf_id字段在初始化后不會(huì)出現(xiàn)變化,因此不需要鎖定. * freeNext通過(guò)buffer_strategy_lock鎖而不是buffer header lock保護(hù). * LWLock可以很好的處理自己的狀態(tài). * 務(wù)請(qǐng)注意的是:buffer header lock不用于控制buffer中的數(shù)據(jù)訪問(wèn)! * * It's assumed that nobody changes the state field while buffer header lock * is held. Thus buffer header lock holder can do complex updates of the * state variable in single write, simultaneously with lock release (cleaning * BM_LOCKED flag). On the other hand, updating of state without holding * buffer header lock is restricted to CAS, which insure that BM_LOCKED flag * is not set. Atomic increment/decrement, OR/AND etc. are not allowed. * 假定在持有buffer header lock的情況下,沒(méi)有人改變狀態(tài)字段. * 持有buffer header lock的進(jìn)程可以執(zhí)行在單個(gè)寫操作中執(zhí)行復(fù)雜的狀態(tài)變量更新, * 同步的釋放鎖(清除BM_LOCKED標(biāo)記). * 換句話說(shuō),如果沒(méi)有持有buffer header lock的狀態(tài)更新,會(huì)受限于CAS, * 這種情況下確保BM_LOCKED沒(méi)有被設(shè)置. * 比如原子的增加/減少(AND/OR)等操作是不允許的. * * An exception is that if we have the buffer pinned, its tag can't change * underneath us, so we can examine the tag without locking the buffer header. * Also, in places we do one-time reads of the flags without bothering to * lock the buffer header; this is generally for situations where we don't * expect the flag bit being tested to be changing. * 一種例外情況是如果我們已有buffer pinned,該buffer的tag不能改變(在本進(jìn)程之下), * 因此不需要鎖定buffer header就可以檢查tag了. * 同時(shí),在執(zhí)行一次性的flags讀取時(shí)不需要鎖定buffer header. * 這種情況通常用于我們不希望正在測(cè)試的flag bit將被改變. * * We can't physically remove items from a disk page if another backend has * the buffer pinned. Hence, a backend may need to wait for all other pins * to go away. This is signaled by storing its own PID into * wait_backend_pid and setting flag bit BM_PIN_COUNT_WAITER. At present, * there can be only one such waiter per buffer. * 如果其他進(jìn)程有buffer pinned,那么進(jìn)程不能物理的從磁盤頁(yè)面中刪除items. * 因此,后臺(tái)進(jìn)程需要等待其他pins清除.這可以通過(guò)存儲(chǔ)它自己的PID到wait_backend_pid中, * 并設(shè)置標(biāo)記位BM_PIN_COUNT_WAITER. * 目前,每個(gè)緩沖區(qū)只能由一個(gè)等待進(jìn)程. * * We use this same struct for local buffer headers, but the locks are not * used and not all of the flag bits are useful either. To avoid unnecessary * overhead, manipulations of the state field should be done without actual * atomic operations (i.e. only pg_atomic_read_u32() and * pg_atomic_unlocked_write_u32()). * 本地緩沖頭部使用同樣的結(jié)構(gòu),但并不需要使用locks,而且并不是所有的標(biāo)記位都使用. * 為了避免不必要的負(fù)載,狀態(tài)域的維護(hù)不需要實(shí)際的原子操作 * (比如只有pg_atomic_read_u32() and pg_atomic_unlocked_write_u32()) * * Be careful to avoid increasing the size of the struct when adding or * reordering members. Keeping it below 64 bytes (the most common CPU * cache line size) is fairly important for performance. * 在增加或者記錄成員變量時(shí),小心避免增加結(jié)構(gòu)體的大小. * 保持結(jié)構(gòu)體大小在64字節(jié)內(nèi)(通常的CPU緩存線大小)對(duì)于性能是非常重要的. */ typedef struct BufferDesc { //buffer tag BufferTag tag; /* ID of page contained in buffer */ //buffer索引編號(hào)(0開始),指向相應(yīng)的buffer pool slot int buf_id; /* buffer's index number (from 0) */ /* state of the tag, containing flags, refcount and usagecount */ //tag狀態(tài),包括flags/refcount和usagecount pg_atomic_uint32 state; //pin-count等待進(jìn)程ID int wait_backend_pid; /* backend PID of pin-count waiter */ //空閑鏈表鏈中下一個(gè)空閑的buffer int freeNext; /* link in freelist chain */ //緩沖區(qū)內(nèi)容鎖 LWLock content_lock; /* to lock access to buffer contents */ } BufferDesc;
BufferTag
Buffer tag標(biāo)記了buffer存儲(chǔ)的是磁盤中哪個(gè)block
/* * Buffer tag identifies which disk block the buffer contains. * Buffer tag標(biāo)記了buffer存儲(chǔ)的是磁盤中哪個(gè)block * * Note: the BufferTag data must be sufficient to determine where to write the * block, without reference to pg_class or pg_tablespace entries. It's * possible that the backend flushing the buffer doesn't even believe the * relation is visible yet (its xact may have started before the xact that * created the rel). The storage manager must be able to cope anyway. * 注意:BufferTag必須足以確定如何寫block而不需要參照pg_class或者pg_tablespace數(shù)據(jù)字典信息. * 有可能后臺(tái)進(jìn)程在刷新緩沖區(qū)的時(shí)候深圳不相信關(guān)系是可見的(事務(wù)可能在創(chuàng)建rel的事務(wù)之前). * 存儲(chǔ)管理器必須可以處理這些事情. * * Note: if there's any pad bytes in the struct, INIT_BUFFERTAG will have * to be fixed to zero them, since this struct is used as a hash key. * 注意:如果在結(jié)構(gòu)體中有填充的字節(jié),INIT_BUFFERTAG必須將它們固定為零,因?yàn)檫@個(gè)結(jié)構(gòu)體用作散列鍵. */ typedef struct buftag { //物理relation標(biāo)識(shí)符 RelFileNode rnode; /* physical relation identifier */ ForkNumber forkNum; //相對(duì)于relation起始的塊號(hào) BlockNumber blockNum; /* blknum relative to begin of reln */ } BufferTag;
HTAB
哈希表的頂層控制結(jié)構(gòu).
/* * Top control structure for a hashtable --- in a shared table, each backend * has its own copy (OK since no fields change at runtime) * 哈希表的頂層控制結(jié)構(gòu). * 在這個(gè)共享哈希表中,每一個(gè)后臺(tái)進(jìn)程都有自己的拷貝 * (之所以沒(méi)有問(wèn)題是因?yàn)閒ork出來(lái)后,在運(yùn)行期沒(méi)有字段會(huì)變化) */ struct HTAB { //指向共享的控制信息 HASHHDR *hctl; /* => shared control information */ //段開始目錄 HASHSEGMENT *dir; /* directory of segment starts */ //哈希函數(shù) HashValueFunc hash; /* hash function */ //哈希鍵比較函數(shù) HashCompareFunc match; /* key comparison function */ //哈希鍵拷貝函數(shù) HashCopyFunc keycopy; /* key copying function */ //內(nèi)存分配器 HashAllocFunc alloc; /* memory allocator */ //內(nèi)存上下文 MemoryContext hcxt; /* memory context if default allocator used */ //表名(用于錯(cuò)誤信息) char *tabname; /* table name (for error messages) */ //如在共享內(nèi)存中,則為T bool isshared; /* true if table is in shared memory */ //如為T,則固定大小不能擴(kuò)展 bool isfixed; /* if true, don't enlarge */ /* freezing a shared table isn't allowed, so we can keep state here */ //不允許凍結(jié)共享表,因此這里會(huì)保存相關(guān)狀態(tài) bool frozen; /* true = no more inserts allowed */ /* We keep local copies of these fixed values to reduce contention */ //保存這些固定值的本地拷貝,以減少?zèng)_突 //哈希鍵長(zhǎng)度(以字節(jié)為單位) Size keysize; /* hash key length in bytes */ //段大小,必須為2的冪 long ssize; /* segment size --- must be power of 2 */ //段偏移,ssize的對(duì)數(shù) int sshift; /* segment shift = log2(ssize) */ }; /* * Header structure for a hash table --- contains all changeable info * 哈希表的頭部結(jié)構(gòu) -- 存儲(chǔ)所有可變信息 * * In a shared-memory hash table, the HASHHDR is in shared memory, while * each backend has a local HTAB struct. For a non-shared table, there isn't * any functional difference between HASHHDR and HTAB, but we separate them * anyway to share code between shared and non-shared tables. * 在共享內(nèi)存哈希表中,HASHHDR位于共享內(nèi)存中,每一個(gè)后臺(tái)進(jìn)程都有一個(gè)本地HTAB結(jié)構(gòu). * 對(duì)于非共享哈希表,HASHHDR和HTAB沒(méi)有任何功能性的不同, * 但無(wú)論如何,我們還是把它們區(qū)分為共享和非共享表. */ struct HASHHDR { /* * The freelist can become a point of contention in high-concurrency hash * tables, so we use an array of freelists, each with its own mutex and * nentries count, instead of just a single one. Although the freelists * normally operate independently, we will scavenge entries from freelists * other than a hashcode's default freelist when necessary. * 在高并發(fā)的哈希表中,空閑鏈表會(huì)成為競(jìng)爭(zhēng)熱點(diǎn),因此我們使用空閑鏈表數(shù)組, * 數(shù)組中的每一個(gè)元素都有自己的mutex和條目統(tǒng)計(jì),而不是使用一個(gè). * * If the hash table is not partitioned, only freeList[0] is used and its * spinlock is not used at all; callers' locking is assumed sufficient. * 如果哈希表沒(méi)有分區(qū),那么只有freelist[0]元素是有用的,自旋鎖沒(méi)有任何用處; * 調(diào)用者鎖定被認(rèn)為已足夠OK. */ FreeListData freeList[NUM_FREELISTS]; /* These fields can change, but not in a partitioned table */ //這些域字段可以改變,但不適用于分區(qū)表 /* Also, dsize can't change in a shared table, even if unpartitioned */ //同時(shí),就算是非分區(qū)表,共享表的dsize也不能改變 //目錄大小 long dsize; /* directory size */ //已分配的段大小(<= dbsize) long nsegs; /* number of allocated segments (<= dsize) */ //正在使用的最大桶ID uint32 max_bucket; /* ID of maximum bucket in use */ //進(jìn)入整個(gè)哈希表的模掩碼 uint32 high_mask; /* mask to modulo into entire table */ //進(jìn)入低于半個(gè)哈希表的模掩碼 uint32 low_mask; /* mask to modulo into lower half of table */ /* These fields are fixed at hashtable creation */ //下面這些字段在哈希表創(chuàng)建時(shí)已固定 //哈希鍵大小(以字節(jié)為單位) Size keysize; /* hash key length in bytes */ //所有用戶元素大小(以字節(jié)為單位) Size entrysize; /* total user element size in bytes */ //分區(qū)個(gè)數(shù)(2的冪),或者為0 long num_partitions; /* # partitions (must be power of 2), or 0 */ //目標(biāo)的填充因子 long ffactor; /* target fill factor */ //如目錄是固定大小,則該值為dsize的上限值 long max_dsize; /* 'dsize' limit if directory is fixed size */ //段大小,必須是2的冪 long ssize; /* segment size --- must be power of 2 */ //端偏移,ssize的對(duì)數(shù) int sshift; /* segment shift = log2(ssize) */ //一次性分配的條目個(gè)數(shù) int nelem_alloc; /* number of entries to allocate at once */ #ifdef HASH_STATISTICS /* * Count statistics here. NB: stats code doesn't bother with mutex, so * counts could be corrupted a bit in a partitioned table. * 統(tǒng)計(jì)信息. * 注意:統(tǒng)計(jì)相關(guān)的代碼不會(huì)影響mutex,因此對(duì)于分區(qū)表,統(tǒng)計(jì)可能有一點(diǎn)點(diǎn)問(wèn)題 */ long accesses; long collisions; #endif }; /* * Per-freelist data. * 空閑鏈表數(shù)據(jù). * * In a partitioned hash table, each freelist is associated with a specific * set of hashcodes, as determined by the FREELIST_IDX() macro below. * nentries tracks the number of live hashtable entries having those hashcodes * (NOT the number of entries in the freelist, as you might expect). * 在一個(gè)分區(qū)哈希表中,每一個(gè)空閑鏈表與特定的hashcodes集合相關(guān),通過(guò)下面的FREELIST_IDX()宏進(jìn)行定義. * nentries跟蹤有這些hashcodes的仍存活的hashtable條目個(gè)數(shù). * (注意不要搞錯(cuò),不是空閑的條目個(gè)數(shù)) * * The coverage of a freelist might be more or less than one partition, so it * needs its own lock rather than relying on caller locking. Relying on that * wouldn't work even if the coverage was the same, because of the occasional * need to "borrow" entries from another freelist; see get_hash_entry(). * 空閑鏈表的覆蓋范圍可能比一個(gè)分區(qū)多或少,因此需要自己的鎖而不能僅僅依賴調(diào)用者的鎖. * 依賴調(diào)用者鎖在覆蓋面一樣的情況下也不會(huì)起效,因?yàn)榕紶栃枰獜牧硪粋€(gè)自由列表“借用”條目,詳細(xì)參見get_hash_entry() * * Using an array of FreeListData instead of separate arrays of mutexes, * nentries and freeLists helps to reduce sharing of cache lines between * different mutexes. * 使用FreeListData數(shù)組而不是一個(gè)獨(dú)立的mutexes,nentries和freelists數(shù)組有助于減少不同mutexes之間的緩存線共享. */ typedef struct { //該空閑鏈表的自旋鎖 slock_t mutex; /* spinlock for this freelist */ //相關(guān)桶中的條目個(gè)數(shù) long nentries; /* number of entries in associated buckets */ //空閑元素鏈 HASHELEMENT *freeList; /* chain of free elements */ } FreeListData; /* * HASHELEMENT is the private part of a hashtable entry. The caller's data * follows the HASHELEMENT structure (on a MAXALIGN'd boundary). The hash key * is expected to be at the start of the caller's hash entry data structure. * HASHELEMENT是哈希表?xiàng)l目的私有部分. * 調(diào)用者的數(shù)據(jù)按照HASHELEMENT結(jié)構(gòu)組織(位于MAXALIGN的邊界). * 哈希鍵應(yīng)位于調(diào)用者h(yuǎn)ash條目數(shù)據(jù)結(jié)構(gòu)的開始位置. */ typedef struct HASHELEMENT { //鏈接到相同桶中的下一個(gè)條目 struct HASHELEMENT *link; /* link to next entry in same bucket */ //該條目的哈希函數(shù)結(jié)果 uint32 hashvalue; /* hash function result for this entry */ } HASHELEMENT; /* Hash table header struct is an opaque type known only within dynahash.c */ //哈希表頭部結(jié)構(gòu),非透明類型,用于dynahash.c typedef struct HASHHDR HASHHDR; /* Hash table control struct is an opaque type known only within dynahash.c */ //哈希表控制結(jié)構(gòu),非透明類型,用于dynahash.c typedef struct HTAB HTAB; /* Parameter data structure for hash_create */ //hash_create使用的參數(shù)數(shù)據(jù)結(jié)構(gòu) /* Only those fields indicated by hash_flags need be set */ //根據(jù)hash_flags標(biāo)記設(shè)置相應(yīng)的字段 typedef struct HASHCTL { //分區(qū)個(gè)數(shù)(必須是2的冪) long num_partitions; /* # partitions (must be power of 2) */ //段大小 long ssize; /* segment size */ //初始化目錄大小 long dsize; /* (initial) directory size */ //dsize上限 long max_dsize; /* limit to dsize if dir size is limited */ //填充因子 long ffactor; /* fill factor */ //哈希鍵大小(字節(jié)為單位) Size keysize; /* hash key length in bytes */ //參見上述數(shù)據(jù)結(jié)構(gòu)注釋 Size entrysize; /* total user element size in bytes */ // HashValueFunc hash; /* hash function */ HashCompareFunc match; /* key comparison function */ HashCopyFunc keycopy; /* key copying function */ HashAllocFunc alloc; /* memory allocator */ MemoryContext hcxt; /* memory context to use for allocations */ //共享內(nèi)存中的哈希頭部結(jié)構(gòu)地址 HASHHDR *hctl; /* location of header in shared mem */ } HASHCTL; /* A hash bucket is a linked list of HASHELEMENTs */ //哈希桶是HASHELEMENTs鏈表 typedef HASHELEMENT *HASHBUCKET; /* A hash segment is an array of bucket headers */ //hash segment是桶數(shù)組 typedef HASHBUCKET *HASHSEGMENT; /* * Hash functions must have this signature. * Hash函數(shù)必須有它自己的標(biāo)識(shí) */ typedef uint32 (*HashValueFunc) (const void *key, Size keysize); /* * Key comparison functions must have this signature. Comparison functions * return zero for match, nonzero for no match. (The comparison function * definition is designed to allow memcmp() and strncmp() to be used directly * as key comparison functions.) * 哈希鍵對(duì)比函數(shù)必須有自己的標(biāo)識(shí). * 如匹配則對(duì)比函數(shù)返回0,不匹配返回非0. * (對(duì)比函數(shù)定義被設(shè)計(jì)為允許在對(duì)比鍵值時(shí)可直接使用memcmp()和strncmp()) */ typedef int (*HashCompareFunc) (const void *key1, const void *key2, Size keysize); /* * Key copying functions must have this signature. The return value is not * used. (The definition is set up to allow memcpy() and strlcpy() to be * used directly.) * 鍵拷貝函數(shù)必須有自己的標(biāo)識(shí). * 返回值無(wú)用. */ typedef void *(*HashCopyFunc) (void *dest, const void *src, Size keysize); /* * Space allocation function for a hashtable --- designed to match malloc(). * Note: there is no free function API; can't destroy a hashtable unless you * use the default allocator. * 哈希表的恐懼分配函數(shù) -- 被設(shè)計(jì)為與malloc()函數(shù)匹配. * 注意:這里沒(méi)有釋放函數(shù)API;不能銷毀哈希表,除非使用默認(rèn)的分配器. */ typedef void *(*HashAllocFunc) (Size request);
BufferLookupEnt
/* entry for buffer lookup hashtable */ //檢索hash表的條目 typedef struct { //磁盤page的tag BufferTag key; /* Tag of a disk page */ //相關(guān)聯(lián)的buffer ID int id; /* Associated buffer ID */ } BufferLookupEnt;
BufTableInsert源碼很簡(jiǎn)單,重點(diǎn)是需要理解HTAB數(shù)據(jù)結(jié)構(gòu),即全局變量SharedBufHash的數(shù)據(jù)結(jié)構(gòu).
/* * BufTableInsert * Insert a hashtable entry for given tag and buffer ID, * unless an entry already exists for that tag * BufTableInsert * 給定tag和buffer ID,插入到哈希表中,如該tag相應(yīng)的條目已存在,則不處理. * * Returns -1 on successful insertion. If a conflicting entry exists * already, returns the buffer ID in that entry. * 如成功插入,則返回-1.如沖突的條目已存在,則返回條目的buffer ID. * * Caller must hold exclusive lock on BufMappingLock for tag's partition * 調(diào)用者必須持有tag分區(qū)BufMappingLock獨(dú)占鎖. */ int BufTableInsert(BufferTag *tagPtr, uint32 hashcode, int buf_id) { BufferLookupEnt *result; bool found; Assert(buf_id >= 0); /* -1 is reserved for not-in-table */ Assert(tagPtr->blockNum != P_NEW); /* invalid tag */ //static HTAB *SharedBufHash; result = (BufferLookupEnt *) hash_search_with_hash_value(SharedBufHash, (void *) tagPtr, hashcode, HASH_ENTER, &found); if (found) /* found something already in the table */ return result->id; result->id = buf_id; return -1; }
測(cè)試腳本,查詢數(shù)據(jù)表:
10:01:54 (xdb@[local]:5432)testdb=# select * from t1 limit 10;
啟動(dòng)gdb,設(shè)置斷點(diǎn)
(gdb) (gdb) b BufTableInsert Breakpoint 1 at 0x875c92: file buf_table.c, line 125. (gdb) c Continuing. Breakpoint 1, BufTableInsert (tagPtr=0x7fff0cba0ef0, hashcode=1398580903, buf_id=101) at buf_table.c:125 125 Assert(buf_id >= 0); /* -1 is reserved for not-in-table */ (gdb)
輸入?yún)?shù)
tagPtr-BufferTag結(jié)構(gòu)體
hashcode=1398580903,
buf_id=101
(gdb) p *tagPtr $1 = {rnode = {spcNode = 1663, dbNode = 16402, relNode = 51439}, forkNum = MAIN_FORKNUM, blockNum = 0}
調(diào)用hash_search_with_hash_value,重點(diǎn)考察SharedBufHash(HTAB指針)
(gdb) n 129 hash_search_with_hash_value(SharedBufHash,
SharedBufHash
(gdb) p *SharedBufHash $2 = {hctl = 0x7f5489004380, dir = 0x7f54890046d8, hash = 0xa3bf74 <tag_hash>, match = 0x4791a0 <memcmp@plt>, keycopy = 0x479690 <memcpy@plt>, alloc = 0x89250b <ShmemAllocNoError>, hcxt = 0x0, tabname = 0x1fbf1d8 "Shared Buffer Lookup Table", isshared = true, isfixed = false, frozen = false, keysize = 20, ssize = 256, sshift = 8} (gdb)
SharedBufHash->hctl,HASHHDR結(jié)構(gòu)體
freeList是一個(gè)數(shù)組
num_partitions是分區(qū)個(gè)數(shù),默認(rèn)為128
(gdb) p *SharedBufHash->hctl $3 = {freeList = {{mutex = 0 '\000', nentries = 3, freeList = 0x7f5489119700}, {mutex = 0 '\000', nentries = 2, freeList = 0x7f548912d828}, {mutex = 0 '\000', nentries = 4, freeList = 0x7f54891418d8}, {mutex = 0 '\000', nentries = 3, freeList = 0x7f5489155a00}, {mutex = 0 '\000', nentries = 8, freeList = 0x7f5489169a38}, { mutex = 0 '\000', nentries = 3, freeList = 0x7f548917dc00}, {mutex = 0 '\000', nentries = 5, freeList = 0x7f5489191cb0}, {mutex = 0 '\000', nentries = 3, freeList = 0x7f54891a5e00}, {mutex = 0 '\000', nentries = 1, freeList = 0x7f54891b9f50}, {mutex = 0 '\000', nentries = 3, freeList = 0x7f54891ce000}, { mutex = 0 '\000', nentries = 3, freeList = 0x7f54891e2100}, {mutex = 0 '\000', nentries = 5, freeList = 0x7f54891f61b0}, {mutex = 0 '\000', nentries = 4, freeList = 0x7f548920a2d8}, {mutex = 0 '\000', nentries = 2, freeList = 0x7f548921e428}, {mutex = 0 '\000', nentries = 2, freeList = 0x7f5489232528}, { mutex = 0 '\000', nentries = 4, freeList = 0x7f54892465d8}, {mutex = 0 '\000', nentries = 3, freeList = 0x7f548925a700}, {mutex = 0 '\000', nentries = 3, freeList = 0x7f548926e800}, {mutex = 0 '\000', nentries = 5, freeList = 0x7f54892828b0}, {mutex = 0 '\000', nentries = 2, freeList = 0x7f5489296a28}, { mutex = 0 '\000', nentries = 4, freeList = 0x7f54892aaad8}, {mutex = 0 '\000', nentries = 4, freeList = 0x7f54892bebd8}, {mutex = 0 '\000', nentries = 5, freeList = 0x7f54892d2cb0}, {mutex = 0 '\000', nentries = 0, freeList = 0x7f54892e6e78}, {mutex = 0 '\000', nentries = 2, freeList = 0x7f54892faf28}, { mutex = 0 '\000', nentries = 3, freeList = 0x7f548930f000}, {mutex = 0 '\000', nentries = 4, freeList = 0x7f54893230d8}, {mutex = 0 '\000', nentries = 4, freeList = 0x7f54893371d8}, {mutex = 0 '\000', nentries = 2, freeList = 0x7f548934b328}, {mutex = 0 '\000', nentries = 1, freeList = 0x7f548935f450}, { mutex = 0 '\000', nentries = 4, freeList = 0x7f54893734d8}, {mutex = 0 '\000', nentries = 3, freeList = 0x7f5489387600}}, dsize = 512, nsegs = 512, max_bucket = 131071, high_mask = 262143, low_mask = 131071, keysize = 20, entrysize = 24, num_partitions = 128, ffactor = 1, max_dsize = 512, ssize = 256, sshift = 8, nelem_alloc = 51} (gdb) (gdb) p *SharedBufHash->hctl->freeList[0].freeList $4 = {link = 0x7f54891196d8, hashvalue = 0} (gdb) p *SharedBufHash->hctl->freeList[0].freeList.link $5 = {link = 0x7f54891196b0, hashvalue = 0} (gdb)
SharedBufHash->dir,段開始目錄
(gdb) p *SharedBufHash->dir $6 = (HASHSEGMENT) 0x7f5489005700 (gdb) p **SharedBufHash->dir $7 = (HASHBUCKET) 0x0 (gdb) p *SharedBufHash->dir[0] $8 = (HASHBUCKET) 0x0 (gdb) p *SharedBufHash->dir[1] $9 = (HASHBUCKET) 0x0 (gdb)
哈希函數(shù)為tag_hash
哈希鍵比較函數(shù)是memcmp
@plt
哈希鍵拷貝函數(shù)是memcpy
@plt
內(nèi)存分配器是ShmemAllocNoError
內(nèi)存上下文為NULL
表名是Shared Buffer Lookup Table
共享內(nèi)存(isshared=T)
非固定/非凍結(jié)/哈希鍵長(zhǎng)度為20B/段大小為256/段偏移為8
執(zhí)行hash_search_with_hash_value,查看相關(guān)信息
(gdb) n 128 result = (BufferLookupEnt *) (gdb) 135 if (found) /* found something already in the table */ (gdb) p *SharedBufHash $10 = {hctl = 0x7f5489004380, dir = 0x7f54890046d8, hash = 0xa3bf74 <tag_hash>, match = 0x4791a0 <memcmp@plt>, keycopy = 0x479690 <memcpy@plt>, alloc = 0x89250b <ShmemAllocNoError>, hcxt = 0x0, tabname = 0x1fbf1d8 "Shared Buffer Lookup Table", isshared = true, isfixed = false, frozen = false, keysize = 20, ssize = 256, sshift = 8} (gdb) p *SharedBufHash->hctl $11 = {freeList = {{mutex = 0 '\000', nentries = 3, freeList = 0x7f5489119700}, {mutex = 0 '\000', nentries = 2, freeList = 0x7f548912d828}, {mutex = 0 '\000', nentries = 4, freeList = 0x7f54891418d8}, {mutex = 0 '\000', nentries = 3, freeList = 0x7f5489155a00}, {mutex = 0 '\000', nentries = 8, freeList = 0x7f5489169a38}, { mutex = 0 '\000', nentries = 3, freeList = 0x7f548917dc00}, {mutex = 0 '\000', nentries = 5, freeList = 0x7f5489191cb0}, {mutex = 0 '\000', nentries = 4, freeList = 0x7f54891a5dd8}, {mutex = 0 '\000', nentries = 1, freeList = 0x7f54891b9f50}, {mutex = 0 '\000', nentries = 3, freeList = 0x7f54891ce000}, { mutex = 0 '\000', nentries = 3, freeList = 0x7f54891e2100}, {mutex = 0 '\000', nentries = 5, freeList = 0x7f54891f61b0}, {mutex = 0 '\000', nentries = 4, freeList = 0x7f548920a2d8}, {mutex = 0 '\000', nentries = 2, freeList = 0x7f548921e428}, {mutex = 0 '\000', nentries = 2, freeList = 0x7f5489232528}, { mutex = 0 '\000', nentries = 4, freeList = 0x7f54892465d8}, {mutex = 0 '\000', nentries = 3, freeList = 0x7f548925a700}, {mutex = 0 '\000', nentries = 3, freeList = 0x7f548926e800}, {mutex = 0 '\000', nentries = 5, freeList = 0x7f54892828b0}, {mutex = 0 '\000', nentries = 2, freeList = 0x7f5489296a28}, { mutex = 0 '\000', nentries = 4, freeList = 0x7f54892aaad8}, {mutex = 0 '\000', nentries = 4, freeList = 0x7f54892bebd8}, {mutex = 0 '\000', nentries = 5, freeList = 0x7f54892d2cb0}, {mutex = 0 '\000', nentries = 0, freeList = 0x7f54892e6e78}, {mutex = 0 '\000', nentries = 2, freeList = 0x7f54892faf28}, { mutex = 0 '\000', nentries = 3, freeList = 0x7f548930f000}, {mutex = 0 '\000', nentries = 4, freeList = 0x7f54893230d8}, {mutex = 0 '\000', nentries = 4, freeList = 0x7f54893371d8}, {mutex = 0 '\000', nentries = 2, freeList = 0x7f548934b328}, {mutex = 0 '\000', nentries = 1, freeList = 0x7f548935f450}, { mutex = 0 '\000', nentries = 4, freeList = 0x7f54893734d8}, {mutex = 0 '\000', nentries = 3, freeList = 0x7f5489387600}}, dsize = 512, nsegs = 512, max_bucket = 131071, high_mask = 262143, low_mask = 131071, keysize = 20, entrysize = 24, num_partitions = 128, ffactor = 1, max_dsize = 512, ssize = 256, sshift = 8, nelem_alloc = 51} (gdb) p **SharedBufHash->dir $12 = (HASHBUCKET) 0x0 (gdb) p *SharedBufHash->dir $13 = (HASHSEGMENT) 0x7f5489005700 (gdb) p result $14 = (BufferLookupEnt *) 0x7f54891a5e10 (gdb) p *result $15 = {key = {rnode = {spcNode = 1663, dbNode = 16402, relNode = 51439}, forkNum = MAIN_FORKNUM, blockNum = 0}, id = 0} (gdb) p found $16 = false
完成調(diào)用,返回
(gdb) n 138 result->id = buf_id; (gdb) 140 return -1; (gdb) 141 } (gdb) BufferAlloc (smgr=0x204f430, relpersistence=112 'p', forkNum=MAIN_FORKNUM, blockNum=0, strategy=0x0, foundPtr=0x7fff0cba0fa3) at bufmgr.c:1216 1216 if (buf_id >= 0) (gdb)
“PostgreSQL中BufTableInsert函數(shù)有什么作用”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。