C comments: improve description of GiST NSN and GistBuildLSN
authorBruce Momjian <bruce@momjian.us>
Wed, 10 Mar 2021 22:03:10 +0000 (17:03 -0500)
committerBruce Momjian <bruce@momjian.us>
Wed, 10 Mar 2021 22:03:10 +0000 (17:03 -0500)
GiST indexes are complex, so adding more details in the code might help
someone.

Discussion: https://postgr.es/m/20210302164021.GA364@momjian.us

src/backend/access/gist/README
src/include/access/gist.h

index 8ca0cf78cc97f497fa3baf9e8aded7b17100dc28..25cab0047b657630a9f7983b6e31e04100f98502 100644 (file)
@@ -10,6 +10,7 @@ GiST stands for Generalized Search Tree. It was introduced in the seminal paper
 Jeffrey F. Naughton, Avi Pfeffer:
 
     http://www.sai.msu.su/~megera/postgres/gist/papers/gist.ps
+    https://dsf.berkeley.edu/papers/sigmod97-gist.pdf
 
 and implemented by J. Hellerstein and P. Aoki in an early version of
 PostgreSQL (more details are available from The GiST Indexing Project
index aa5f1763dd0a6ec69da65fd66fcda7bc8a942680..4b06575d98702f4e4a455c20fe5106f41a2d108e 100644 (file)
 #define F_HAS_GARBAGE          (1 << 4)        /* some tuples on the page are dead,
                                                                                 * but not deleted yet */
 
-/* NSN - node sequence number, a special-purpose LSN */
+/*
+ * NSN (node sequence number) is a special-purpose LSN which is stored on each
+ * index page in GISTPageOpaqueData and updated only during page splits.  By
+ * recording the parent's LSN in GISTSearchItem.parentlsn, it is possible to
+ * detect concurrent child page splits by checking if parentlsn < child's NSN,
+ * and handle them properly.  The child page's LSN is insufficient for this
+ * purpose since it is updated for every page change.
+ */
 typedef XLogRecPtr GistNSN;
 
 /*
- * A bogus LSN / NSN value used during index build. Must be smaller than any
- * real or fake unlogged LSN, so that after an index build finishes, all the
- * splits are considered completed.
+ * A fake LSN / NSN value used during index builds. Must be smaller than any
+ * real or fake (unlogged) LSN generated after the index build completes so
+ * that all splits are considered complete.
  */
 #define GistBuildLSN   ((XLogRecPtr) 1)