27
27
11) What is configure all about?
28
28
12) How do I add a new port?
29
29
13) What is CommandCounterIncrement()?
30
+ 13) Why don't we use threads in the backend?
30
31
_________________________________________________________________
31
32
32
33
1) What tools are available for developers?
33
34
34
35
Aside from the User documentation mentioned in the regular FAQ, there
35
36
are several development tools available. First, all the files in the
36
37
/tools directory are designed for developers.
37
- RELEASE_CHANGES changes we have to make for each release
38
- SQL_keywords standard SQL'92 keywords
39
- backend description/flowchart of the backend directorie
40
- s
41
- ccsym find standard defines made by your compiler
42
- entab converts tabs to spaces, used by pgindent
43
- find_static finds functions that could be made static
44
- find_typedef get a list of typedefs in the source code
45
- make_ctags make vi 'tags' file in each directory
46
- make_diff make *.orig and diffs of source
47
- make_etags make emacs 'etags' files
48
- make_keywords.README make comparison of our keywords and SQL'92
49
- make_mkid make mkid ID files
50
- mkldexport create AIX exports file
51
- pgindent indents C source files
52
- pginclude scripts for adding/removing include files
53
- unused_oids in pgsql/src/include/catalog
38
+ RELEASE_CHANGES changes we have to make for each release
39
+ SQL_keywords standard SQL'92 keywords
40
+ backend description/flowchart of the backend directories
41
+ ccsym find standard defines made by your compiler
42
+ entab converts tabs to spaces, used by pgindent
43
+ find_static finds functions that could be made static
44
+ find_typedef get a list of typedefs in the source code
45
+ make_ctags make vi 'tags' file in each directory
46
+ make_diff make *.orig and diffs of source
47
+ make_etags make emacs 'etags' files
48
+ make_keywords.README make comparison of our keywords and SQL'92
49
+ make_mkid make mkid ID files
50
+ mkldexport create AIX exports file
51
+ pgindent indents C source files
52
+ pginclude scripts for adding/removing include files
53
+ unused_oids in pgsql/src/include/catalog
54
54
55
55
Let me note some of these. If you point your browser at the
56
56
file:/usr/local/src/pgsql/src/tools/backend/index.html directory, you
71
71
support this via tags or etags files.
72
72
73
73
Third, you need to get id-utils from:
74
- ftp://alpha.gnu.org/gnu/id-utils-3.2d.tar.gz
75
- ftp://tug.org/gnu/id-utils-3.2d.tar.gz
76
- ftp://ftp.enst.fr/pub/gnu/gnits/id-utils-3.2d.tar.gz
74
+ ftp://alpha.gnu.org/gnu/id-utils-3.2d.tar.gz
75
+ ftp://tug.org/gnu/id-utils-3.2d.tar.gz
76
+ ftp://ftp.enst.fr/pub/gnu/gnits/id-utils-3.2d.tar.gz
77
77
78
78
By running tools/make_mkid, an archive of source symbols can be
79
79
created that can be rapidly queried like grep or edited. Others prefer
85
85
Our standard format is to indent each code level with one tab, where
86
86
each tab is four spaces. You will need to set your editor to display
87
87
tabs as four spaces:
88
- vi in ~/.exrc:
89
- set tabstop=4
90
- set sw=4
91
- more:
92
- more -x4
93
- less:
94
- less -x4
95
- emacs:
96
- M-x set-variable tab-width
97
- or
98
- ; Cmd to set tab stops &etc for working with PostgreSQL code
88
+ vi in ~/.exrc:
89
+ set tabstop=4
90
+ set sw=4
91
+ more:
92
+ more -x4
93
+ less:
94
+ less -x4
95
+ emacs:
96
+ M-x set-variable tab-width
97
+ or
98
+ ; Cmd to set tab stops & indenting for working with PostgreSQL code
99
99
(c-add-style "pgsql"
100
- '("bsd"
100
+ '("bsd"
101
101
(indent-tabs-mode . t)
102
102
(c-basic-offset . 4)
103
103
(tab-width . 4)
104
- (c-offsets-alist .
104
+ (c-offsets-alist .
105
105
((case-label . +))))
106
106
t) ; t = set this mode on
107
107
108
- and add this to your autoload list (modify file path in macro):
108
+ and add this to your autoload list (modify file path in macro):
109
109
110
- (setq auto-mode-alist
111
- (cons '("\\`/usr/local/src/pgsql/.*\\.[chyl]\\'" . pgsql-
112
- c-mode)
113
- auto-mode-alist))
114
- or
115
- /*
116
- * Local variables:
117
- * tab-width: 4
118
- * c-indent-level: 4
119
- * c-basic-offset: 4
120
- * End:
121
- */
110
+ (setq auto-mode-alist
111
+ (cons '("\\`/usr/local/src/pgsql/.*\\.[chyl]\\'" . pgsql-c-mode)
112
+ auto-mode-alist))
113
+ or
114
+ /*
115
+ * Local variables:
116
+ * tab-width: 4
117
+ * c-indent-level: 4
118
+ * c-basic-offset: 4
119
+ * End:
120
+ */
122
121
123
122
pgindent will the format code by specifying flags to your operating
124
123
system's utility indent.
@@ -174,8 +173,7 @@ c-mode)
174
173
a typical code snipped that loops through a List containing Var
175
174
*'s and processes each one:
176
175
177
-
178
- List *i, *list;
176
+ List *i, *list;
179
177
180
178
foreach(i, list)
181
179
{
@@ -207,17 +205,15 @@ c-mode)
207
205
208
206
You can print nodes easily inside gdb. First, to disable output
209
207
truncation when you use the gdb print command:
210
-
211
- (gdb) set print elements 0
208
+ (gdb) set print elements 0
212
209
213
210
Instead of printing values in gdb format, you can use the next two
214
211
commands to print out List, Node, and structure contents in a verbose
215
212
format that is easier to understand. List's are unrolled into nodes,
216
213
and nodes are printed in detail. The first prints in a short format,
217
214
and the second in a long format:
218
-
219
- (gdb) call print(any_pointer)
220
- (gdb) call pprint(any_pointer)
215
+ (gdb) call print(any_pointer)
216
+ (gdb) call pprint(any_pointer)
221
217
222
218
The output appears in the postmaster log file, or on your screen if
223
219
you are running a backend directly without a postmaster.
@@ -292,11 +288,11 @@ c-mode)
292
288
tables in columns of type Name. Name is a fixed-length,
293
289
null-terminated type of NAMEDATALEN bytes. (The default value for
294
290
NAMEDATALEN is 32 bytes.)
295
- typedef struct nameData
296
- {
297
- char data[NAMEDATALEN];
298
- } NameData;
299
- typedef NameData *Name;
291
+ typedef struct nameData
292
+ {
293
+ char data[NAMEDATALEN];
294
+ } NameData;
295
+ typedef NameData *Name;
300
296
301
297
Table, column, type, function, and view names that come into the
302
298
backend via user queries are stored as variable-length,
@@ -311,8 +307,8 @@ c-mode)
311
307
9) How do I efficiently access information in tables from the backend code?
312
308
313
309
You first need to find the tuples(rows) you are interested in. There
314
- are two ways. First, SearchSysCache() and related functions allow
315
- you to query the system catalogs. This is the preferred way to access
310
+ are two ways. First, SearchSysCache() and related functions allow you
311
+ to query the system catalogs. This is the preferred way to access
316
312
system tables, because the first call to the cache loads the needed
317
313
rows, and future requests can return the results without accessing the
318
314
base table. The caches use system table indexes to look up tuples. A
@@ -321,13 +317,14 @@ c-mode)
321
317
src/backend/utils/cache/lsyscache.c contains many column-specific
322
318
cache lookup functions.
323
319
324
- The rows returned are cache-owned versions of the heap rows. Therefore,
325
- you must not modify or delete the tuple returned by SearchSysCache().
326
- What you *should* do is release it with ReleaseSysCache() when you are
327
- done using it; this informs the cache that it can discard that tuple
328
- if necessary. If you neglect to call ReleaseSysCache(), then the cache
329
- entry will remain locked in the cache until end of transaction, which is
330
- tolerable but not very desirable.
320
+ The rows returned are cache-owned versions of the heap rows.
321
+ Therefore, you must not modify or delete the tuple returned by
322
+ SearchSysCache(). What you should do is release it with
323
+ ReleaseSysCache() when you are done using it; this informs the cache
324
+ that it can discard that tuple if necessary. If you neglect to call
325
+ ReleaseSysCache(), then the cache entry will remain locked in the
326
+ cache until end of transaction, which is tolerable but not very
327
+ desirable.
331
328
332
329
If you can't use the system cache, you will need to retrieve the data
333
330
directly from the heap table, using the buffer cache that is shared by
@@ -344,28 +341,26 @@ c-mode)
344
341
While scans automatically lock/unlock rows from the buffer cache, with
345
342
heap_fetch(), you must pass a Buffer pointer, and ReleaseBuffer() it
346
343
when completed.
344
+
345
+ Once you have the row, you can get data that is common to all tuples,
346
+ like t_self and t_oid, by merely accessing the HeapTuple structure
347
+ entries. If you need a table-specific column, you should take the
348
+ HeapTuple pointer, and use the GETSTRUCT() macro to access the
349
+ table-specific start of the tuple. You then cast the pointer as a
350
+ Form_pg_proc pointer if you are accessing the pg_proc table, or
351
+ Form_pg_type if you are accessing pg_type. You can then access the
352
+ columns by using a structure pointer:
353
+ ((Form_pg_class) GETSTRUCT(tuple))->relnatts
347
354
348
- Once you have the row, you can get data that is common
349
- to all tuples, like t_self and t_oid, by merely accessing the
350
- HeapTuple structure entries. If you need a table-specific column, you
351
- should take the HeapTuple pointer, and use the GETSTRUCT() macro to
352
- access the table-specific start of the tuple. You then cast the
353
- pointer as a Form_pg_proc pointer if you are accessing the pg_proc
354
- table, or Form_pg_type if you are accessing pg_type. You can then
355
- access the columns by using a structure pointer:
356
-
357
- ((Form_pg_class) GETSTRUCT(tuple))->relnatts
358
-
359
- You must not directly change live tuples in this way. The best way
360
- is to use heap_modifytuple() and pass it your original tuple, and the
361
- values you want changed. It returns a palloc'ed tuple, which you
362
- pass to heap_replace(). You can delete tuples by passing the tuple's
363
- t_self to heap_destroy(). You use t_self for heap_update() too.
364
-
365
- Remember, tuples can be either system cache copies, which may go away
366
- after you call ReleaseSysCache(), or read directly from disk buffers,
367
- which go away when you heap_getnext(), heap_endscan, or ReleaseBuffer(),
368
- in the heap_fetch() case. Or it may be a palloc'ed tuple, that you must
355
+ You must not directly change live tuples in this way. The best way is
356
+ to use heap_modifytuple() and pass it your original tuple, and the
357
+ values you want changed. It returns a palloc'ed tuple, which you pass
358
+ to heap_replace(). You can delete tuples by passing the tuple's t_self
359
+ to heap_destroy(). You use t_self for heap_update() too. Remember,
360
+ tuples can be either system cache copies, which may go away after you
361
+ call ReleaseSysCache(), or read directly from disk buffers, which go
362
+ away when you heap_getnext(), heap_endscan, or ReleaseBuffer(), in the
363
+ heap_fetch() case. Or it may be a palloc'ed tuple, that you must
369
364
pfree() when finished.
370
365
371
366
10) What is elog()?
@@ -429,3 +424,12 @@ c-mode)
429
424
to be broken into pieces so each piece can see rows modified by
430
425
previous pieces. CommandCounterIncrement() increments the Command
431
426
Counter, creating a new part of the transaction.
427
+
428
+ 14) Why don't we use threads in the backend?
429
+
430
+ There are several reasons threads are not used:
431
+ * Historically, threads were unsupported and buggy.
432
+ * An error in one backend can corrupt other backends.
433
+ * Speed improvements using threads are small compared to the
434
+ remaining backend startup time.
435
+ * The backend code would be more complex.
0 commit comments