Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5dd9fc7

Browse files
committed
Update FAQ_DEV.
1 parent 5eced96 commit 5dd9fc7

File tree

2 files changed

+597
-552
lines changed

2 files changed

+597
-552
lines changed

doc/FAQ_DEV

Lines changed: 92 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,30 @@
2727
11) What is configure all about?
2828
12) How do I add a new port?
2929
13) What is CommandCounterIncrement()?
30+
13) Why don't we use threads in the backend?
3031
_________________________________________________________________
3132

3233
1) What tools are available for developers?
3334

3435
Aside from the User documentation mentioned in the regular FAQ, there
3536
are several development tools available. First, all the files in the
3637
/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
5454

5555
Let me note some of these. If you point your browser at the
5656
file:/usr/local/src/pgsql/src/tools/backend/index.html directory, you
@@ -71,9 +71,9 @@ s
7171
support this via tags or etags files.
7272

7373
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
7777

7878
By running tools/make_mkid, an archive of source symbols can be
7979
created that can be rapidly queried like grep or edited. Others prefer
@@ -85,40 +85,39 @@ s
8585
Our standard format is to indent each code level with one tab, where
8686
each tab is four spaces. You will need to set your editor to display
8787
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
9999
(c-add-style "pgsql"
100-
'("bsd"
100+
'("bsd"
101101
(indent-tabs-mode . t)
102102
(c-basic-offset . 4)
103103
(tab-width . 4)
104-
(c-offsets-alist .
104+
(c-offsets-alist .
105105
((case-label . +))))
106106
t) ; t = set this mode on
107107

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):
109109

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+
*/
122121

123122
pgindent will the format code by specifying flags to your operating
124123
system's utility indent.
@@ -174,8 +173,7 @@ c-mode)
174173
a typical code snipped that loops through a List containing Var
175174
*'s and processes each one:
176175

177-
178-
List *i, *list;
176+
List *i, *list;
179177

180178
foreach(i, list)
181179
{
@@ -207,17 +205,15 @@ c-mode)
207205

208206
You can print nodes easily inside gdb. First, to disable output
209207
truncation when you use the gdb print command:
210-
211-
(gdb) set print elements 0
208+
(gdb) set print elements 0
212209

213210
Instead of printing values in gdb format, you can use the next two
214211
commands to print out List, Node, and structure contents in a verbose
215212
format that is easier to understand. List's are unrolled into nodes,
216213
and nodes are printed in detail. The first prints in a short format,
217214
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)
221217

222218
The output appears in the postmaster log file, or on your screen if
223219
you are running a backend directly without a postmaster.
@@ -292,11 +288,11 @@ c-mode)
292288
tables in columns of type Name. Name is a fixed-length,
293289
null-terminated type of NAMEDATALEN bytes. (The default value for
294290
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;
300296

301297
Table, column, type, function, and view names that come into the
302298
backend via user queries are stored as variable-length,
@@ -311,8 +307,8 @@ c-mode)
311307
9) How do I efficiently access information in tables from the backend code?
312308

313309
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
316312
system tables, because the first call to the cache loads the needed
317313
rows, and future requests can return the results without accessing the
318314
base table. The caches use system table indexes to look up tuples. A
@@ -321,13 +317,14 @@ c-mode)
321317
src/backend/utils/cache/lsyscache.c contains many column-specific
322318
cache lookup functions.
323319

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.
331328

332329
If you can't use the system cache, you will need to retrieve the data
333330
directly from the heap table, using the buffer cache that is shared by
@@ -344,28 +341,26 @@ c-mode)
344341
While scans automatically lock/unlock rows from the buffer cache, with
345342
heap_fetch(), you must pass a Buffer pointer, and ReleaseBuffer() it
346343
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
347354

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
369364
pfree() when finished.
370365

371366
10) What is elog()?
@@ -429,3 +424,12 @@ c-mode)
429424
to be broken into pieces so each piece can see rows modified by
430425
previous pieces. CommandCounterIncrement() increments the Command
431426
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

Comments
 (0)