summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian1997-09-07 05:04:48 +0000
committerBruce Momjian1997-09-07 05:04:48 +0000
commit1ccd423235a48739d6f7a4d7889705b5f9ecc69b (patch)
tree8001c4e839dfad8f29ceda7f8c5f5dbb8759b564
parent8fecd4febf8357f3cc20383ed29ced484877d5ac (diff)
Massive commit to run PGINDENT on all *.c and *.h files.
-rw-r--r--contrib/array/array_iterator.c321
-rw-r--r--contrib/datetime/datetime_functions.c113
-rw-r--r--contrib/int8/int8.c378
-rw-r--r--contrib/pginterface/halt.c54
-rw-r--r--contrib/pginterface/halt.h3
-rw-r--r--contrib/pginterface/pginsert.c80
-rw-r--r--contrib/pginterface/pginterface.c147
-rw-r--r--contrib/pginterface/pginterface.h14
-rw-r--r--contrib/pginterface/pgnulltest.c126
-rw-r--r--contrib/pginterface/pgwordcount.c34
-rw-r--r--contrib/soundex/soundex.c142
-rw-r--r--contrib/string/string_io.c518
-rw-r--r--src/backend/access/common/heaptuple.c1603
-rw-r--r--src/backend/access/common/heapvalid.c206
-rw-r--r--src/backend/access/common/indextuple.c758
-rw-r--r--src/backend/access/common/indexvalid.c104
-rw-r--r--src/backend/access/common/printtup.c431
-rw-r--r--src/backend/access/common/scankey.c54
-rw-r--r--src/backend/access/common/tupdesc.c890
-rw-r--r--src/backend/access/gist/gist.c2267
-rw-r--r--src/backend/access/gist/gistget.c644
-rw-r--r--src/backend/access/gist/gistscan.c620
-rw-r--r--src/backend/access/gist/giststrat.c123
-rw-r--r--src/backend/access/hash/hash.c767
-rw-r--r--src/backend/access/hash/hashfunc.c411
-rw-r--r--src/backend/access/hash/hashinsert.c386
-rw-r--r--src/backend/access/hash/hashovfl.c1065
-rw-r--r--src/backend/access/hash/hashpage.c1107
-rw-r--r--src/backend/access/hash/hashscan.c229
-rw-r--r--src/backend/access/hash/hashsearch.c758
-rw-r--r--src/backend/access/hash/hashstrat.c69
-rw-r--r--src/backend/access/hash/hashutil.c161
-rw-r--r--src/backend/access/heap/heapam.c2531
-rw-r--r--src/backend/access/heap/hio.c229
-rw-r--r--src/backend/access/heap/stats.c531
-rw-r--r--src/backend/access/index/genam.c328
-rw-r--r--src/backend/access/index/indexam.c474
-rw-r--r--src/backend/access/index/istrat.c1095
-rw-r--r--src/backend/access/nbtree/nbtcompare.c201
-rw-r--r--src/backend/access/nbtree/nbtinsert.c2923
-rw-r--r--src/backend/access/nbtree/nbtpage.c902
-rw-r--r--src/backend/access/nbtree/nbtree.c927
-rw-r--r--src/backend/access/nbtree/nbtscan.c267
-rw-r--r--src/backend/access/nbtree/nbtsearch.c2617
-rw-r--r--src/backend/access/nbtree/nbtsort.c1926
-rw-r--r--src/backend/access/nbtree/nbtstrat.c156
-rw-r--r--src/backend/access/nbtree/nbtutils.c623
-rw-r--r--src/backend/access/rtree/rtget.c544
-rw-r--r--src/backend/access/rtree/rtproc.c209
-rw-r--r--src/backend/access/rtree/rtree.c1753
-rw-r--r--src/backend/access/rtree/rtscan.c626
-rw-r--r--src/backend/access/rtree/rtstrat.c346
-rw-r--r--src/backend/access/transam/transam.c964
-rw-r--r--src/backend/access/transam/transsup.c1065
-rw-r--r--src/backend/access/transam/varsup.c1019
-rw-r--r--src/backend/access/transam/xact.c2014
-rw-r--r--src/backend/access/transam/xid.c94
-rw-r--r--src/backend/bootstrap/bootstrap.c1683
-rw-r--r--src/backend/catalog/catalog.c253
-rw-r--r--src/backend/catalog/heap.c2747
-rw-r--r--src/backend/catalog/index.c3019
-rw-r--r--src/backend/catalog/indexing.c808
-rw-r--r--src/backend/catalog/pg_aggregate.c555
-rw-r--r--src/backend/catalog/pg_operator.c1926
-rw-r--r--src/backend/catalog/pg_proc.c445
-rw-r--r--src/backend/catalog/pg_type.c1013
-rw-r--r--src/backend/commands/_deadcode/version.c369
-rw-r--r--src/backend/commands/async.c831
-rw-r--r--src/backend/commands/cluster.c580
-rw-r--r--src/backend/commands/command.c827
-rw-r--r--src/backend/commands/copy.c1884
-rw-r--r--src/backend/commands/creatinh.c1112
-rw-r--r--src/backend/commands/defind.c899
-rw-r--r--src/backend/commands/define.c1113
-rw-r--r--src/backend/commands/explain.c353
-rw-r--r--src/backend/commands/purge.c271
-rw-r--r--src/backend/commands/recipe.c2130
-rw-r--r--src/backend/commands/remove.c796
-rw-r--r--src/backend/commands/rename.c401
-rw-r--r--src/backend/commands/sequence.c924
-rw-r--r--src/backend/commands/trigger.c1050
-rw-r--r--src/backend/commands/vacuum.c3920
-rw-r--r--src/backend/commands/view.c427
-rw-r--r--src/backend/executor/execAmi.c693
-rw-r--r--src/backend/executor/execFlatten.c372
-rw-r--r--src/backend/executor/execJunk.c638
-rw-r--r--src/backend/executor/execMain.c2324
-rw-r--r--src/backend/executor/execProcnode.c820
-rw-r--r--src/backend/executor/execQual.c2665
-rw-r--r--src/backend/executor/execScan.c208
-rw-r--r--src/backend/executor/execTuples.c1526
-rw-r--r--src/backend/executor/execUtils.c1816
-rw-r--r--src/backend/executor/functions.c695
-rw-r--r--src/backend/executor/nodeAgg.c1055
-rw-r--r--src/backend/executor/nodeAppend.c852
-rw-r--r--src/backend/executor/nodeGroup.c632
-rw-r--r--src/backend/executor/nodeHash.c1420
-rw-r--r--src/backend/executor/nodeHashjoin.c1377
-rw-r--r--src/backend/executor/nodeIndexscan.c1623
-rw-r--r--src/backend/executor/nodeMaterial.c631
-rw-r--r--src/backend/executor/nodeMergejoin.c2165
-rw-r--r--src/backend/executor/nodeNestloop.c632
-rw-r--r--src/backend/executor/nodeResult.c454
-rw-r--r--src/backend/executor/nodeSeqscan.c726
-rw-r--r--src/backend/executor/nodeSort.c632
-rw-r--r--src/backend/executor/nodeTee.c899
-rw-r--r--src/backend/executor/nodeUnique.c532
-rw-r--r--src/backend/executor/spi.c1537
-rw-r--r--src/backend/lib/bit.c27
-rw-r--r--src/backend/lib/dllist.c246
-rw-r--r--src/backend/lib/fstack.c146
-rw-r--r--src/backend/lib/hasht.c48
-rw-r--r--src/backend/lib/lispsort.c67
-rw-r--r--src/backend/lib/qsort.c186
-rw-r--r--src/backend/lib/stringinfo.c142
-rw-r--r--src/backend/libpq/auth.c838
-rw-r--r--src/backend/libpq/be-dumpdata.c448
-rw-r--r--src/backend/libpq/be-fsstubs.c470
-rw-r--r--src/backend/libpq/be-pqexec.c613
-rw-r--r--src/backend/libpq/hba.c1336
-rw-r--r--src/backend/libpq/password.c190
-rw-r--r--src/backend/libpq/portal.c946
-rw-r--r--src/backend/libpq/portalbuf.c609
-rw-r--r--src/backend/libpq/pqcomm.c1016
-rw-r--r--src/backend/libpq/pqcomprim.c230
-rw-r--r--src/backend/libpq/pqpacket.c361
-rw-r--r--src/backend/libpq/pqsignal.c78
-rw-r--r--src/backend/libpq/util.c98
-rw-r--r--src/backend/main/main.c71
-rw-r--r--src/backend/nodes/copyfuncs.c2634
-rw-r--r--src/backend/nodes/equalfuncs.c1149
-rw-r--r--src/backend/nodes/list.c685
-rw-r--r--src/backend/nodes/makefuncs.c139
-rw-r--r--src/backend/nodes/nodeFuncs.c119
-rw-r--r--src/backend/nodes/nodes.c36
-rw-r--r--src/backend/nodes/outfuncs.c2640
-rw-r--r--src/backend/nodes/print.c582
-rw-r--r--src/backend/nodes/read.c421
-rw-r--r--src/backend/nodes/readfuncs.c3199
-rw-r--r--src/backend/optimizer/geqo/geqo_copy.c40
-rw-r--r--src/backend/optimizer/geqo/geqo_cx.c132
-rw-r--r--src/backend/optimizer/geqo/geqo_erx.c567
-rw-r--r--src/backend/optimizer/geqo/geqo_eval.c985
-rw-r--r--src/backend/optimizer/geqo/geqo_main.c249
-rw-r--r--src/backend/optimizer/geqo/geqo_misc.c347
-rw-r--r--src/backend/optimizer/geqo/geqo_mutation.c65
-rw-r--r--src/backend/optimizer/geqo/geqo_ox1.c122
-rw-r--r--src/backend/optimizer/geqo/geqo_ox2.c146
-rw-r--r--src/backend/optimizer/geqo/geqo_params.c268
-rw-r--r--src/backend/optimizer/geqo/geqo_paths.c190
-rw-r--r--src/backend/optimizer/geqo/geqo_pmx.c281
-rw-r--r--src/backend/optimizer/geqo/geqo_pool.c301
-rw-r--r--src/backend/optimizer/geqo/geqo_px.c121
-rw-r--r--src/backend/optimizer/geqo/geqo_recombination.c93
-rw-r--r--src/backend/optimizer/geqo/geqo_selection.c88
-rw-r--r--src/backend/optimizer/geqo/minspantree.c317
-rw-r--r--src/backend/optimizer/path/allpaths.c609
-rw-r--r--src/backend/optimizer/path/clausesel.c536
-rw-r--r--src/backend/optimizer/path/costsize.c624
-rw-r--r--src/backend/optimizer/path/hashutils.c174
-rw-r--r--src/backend/optimizer/path/indxpath.c2113
-rw-r--r--src/backend/optimizer/path/joinpath.c1097
-rw-r--r--src/backend/optimizer/path/joinrels.c884
-rw-r--r--src/backend/optimizer/path/joinutils.c679
-rw-r--r--src/backend/optimizer/path/mergeutils.c170
-rw-r--r--src/backend/optimizer/path/orindxpath.c430
-rw-r--r--src/backend/optimizer/path/predmig.c1064
-rw-r--r--src/backend/optimizer/path/prune.c284
-rw-r--r--src/backend/optimizer/path/xfunc.c2192
-rw-r--r--src/backend/optimizer/plan/createplan.c2005
-rw-r--r--src/backend/optimizer/plan/initsplan.c579
-rw-r--r--src/backend/optimizer/plan/planmain.c952
-rw-r--r--src/backend/optimizer/plan/planner.c635
-rw-r--r--src/backend/optimizer/plan/setrefs.c1148
-rw-r--r--src/backend/optimizer/prep/archive.c61
-rw-r--r--src/backend/optimizer/prep/prepqual.c980
-rw-r--r--src/backend/optimizer/prep/preptlist.c544
-rw-r--r--src/backend/optimizer/prep/prepunion.c628
-rw-r--r--src/backend/optimizer/util/clauseinfo.c259
-rw-r--r--src/backend/optimizer/util/clauses.c1026
-rw-r--r--src/backend/optimizer/util/indexnode.c113
-rw-r--r--src/backend/optimizer/util/internal.c48
-rw-r--r--src/backend/optimizer/util/joininfo.c132
-rw-r--r--src/backend/optimizer/util/keys.c261
-rw-r--r--src/backend/optimizer/util/ordering.c154
-rw-r--r--src/backend/optimizer/util/pathnode.c867
-rw-r--r--src/backend/optimizer/util/plancat.c969
-rw-r--r--src/backend/optimizer/util/relnode.c182
-rw-r--r--src/backend/optimizer/util/tlist.c834
-rw-r--r--src/backend/optimizer/util/var.c308
-rw-r--r--src/backend/parser/analyze.c4324
-rw-r--r--src/backend/parser/catalog_utils.c2457
-rw-r--r--src/backend/parser/dbcommands.c409
-rw-r--r--src/backend/parser/keywords.c366
-rw-r--r--src/backend/parser/parse_query.c1340
-rw-r--r--src/backend/parser/parser.c844
-rw-r--r--src/backend/parser/scansup.c173
-rw-r--r--src/backend/parser/sysfunc.c51
-rw-r--r--src/backend/port/BSD44_derived/dl.c56
-rw-r--r--src/backend/port/BSD44_derived/port-protos.h26
-rw-r--r--src/backend/port/aix/dlfcn.c393
-rw-r--r--src/backend/port/aix/dlfcn.h37
-rw-r--r--src/backend/port/aix/port-protos.h8
-rw-r--r--src/backend/port/alpha/port-protos.h14
-rw-r--r--src/backend/port/alpha/port.c23
-rw-r--r--src/backend/port/bsdi/dynloader.c123
-rw-r--r--src/backend/port/bsdi/port-protos.h24
-rw-r--r--src/backend/port/dgux/dynloader.c120
-rw-r--r--src/backend/port/dgux/port-protos.h18
-rw-r--r--src/backend/port/dgux/port.c4
-rw-r--r--src/backend/port/hpux/dynloader.c36
-rw-r--r--src/backend/port/hpux/fixade.h63
-rw-r--r--src/backend/port/hpux/port-protos.h20
-rw-r--r--src/backend/port/hpux/port.c32
-rw-r--r--src/backend/port/hpux/rusagestub.h23
-rw-r--r--src/backend/port/i386_solaris/port-protos.h20
-rw-r--r--src/backend/port/i386_solaris/port.c76
-rw-r--r--src/backend/port/i386_solaris/rusagestub.h25
-rw-r--r--src/backend/port/inet_aton.c96
-rw-r--r--src/backend/port/inet_aton.h2
-rw-r--r--src/backend/port/irix5/port-protos.h16
-rw-r--r--src/backend/port/irix5/port.c6
-rw-r--r--src/backend/port/linux/dynloader.c128
-rw-r--r--src/backend/port/linux/port-protos.h32
-rw-r--r--src/backend/port/linux/port.c4
-rw-r--r--src/backend/port/linuxalpha/machine.h4
-rw-r--r--src/backend/port/linuxalpha/port-protos.h16
-rw-r--r--src/backend/port/linuxalpha/port.c4
-rw-r--r--src/backend/port/nextstep/dynloader.c97
-rw-r--r--src/backend/port/nextstep/port-protos.h24
-rw-r--r--src/backend/port/nextstep/port.c75
-rw-r--r--src/backend/port/sco/port-protos.h16
-rw-r--r--src/backend/port/sco/port.c73
-rw-r--r--src/backend/port/sco/rusagestub.h23
-rw-r--r--src/backend/port/sparc_solaris/port-protos.h28
-rw-r--r--src/backend/port/sparc_solaris/port.c81
-rw-r--r--src/backend/port/sparc_solaris/rusagestub.h25
-rw-r--r--src/backend/port/strerror.c27
-rw-r--r--src/backend/port/sunos4/float.h26
-rw-r--r--src/backend/port/sunos4/port-protos.h18
-rw-r--r--src/backend/port/sunos4/strtol.c96
-rw-r--r--src/backend/port/svr4/port-protos.h18
-rw-r--r--src/backend/port/svr4/port.c98
-rw-r--r--src/backend/port/svr4/rusagestub.h23
-rw-r--r--src/backend/port/ultrix4/dl.h143
-rw-r--r--src/backend/port/ultrix4/dynloader.c85
-rw-r--r--src/backend/port/ultrix4/port-protos.h24
-rw-r--r--src/backend/port/ultrix4/port.c8
-rw-r--r--src/backend/port/ultrix4/strdup.c14
-rw-r--r--src/backend/port/univel/frontend-port-protos.h12
-rw-r--r--src/backend/port/univel/port-protos.h22
-rw-r--r--src/backend/port/univel/port.c111
-rw-r--r--src/backend/port/univel/rusagestub.h23
-rw-r--r--src/backend/postmaster/postmaster.c1949
-rw-r--r--src/backend/regex/engine.c823
-rw-r--r--src/backend/regex/regcomp.c1114
-rw-r--r--src/backend/regex/regerror.c197
-rw-r--r--src/backend/regex/regexec.c156
-rw-r--r--src/backend/regex/regfree.c47
-rw-r--r--src/backend/rewrite/locks.c173
-rw-r--r--src/backend/rewrite/rewriteDefine.c399
-rw-r--r--src/backend/rewrite/rewriteHandler.c1066
-rw-r--r--src/backend/rewrite/rewriteManip.c707
-rw-r--r--src/backend/rewrite/rewriteRemove.c257
-rw-r--r--src/backend/rewrite/rewriteSupport.c428
-rw-r--r--src/backend/storage/buffer/buf_init.c407
-rw-r--r--src/backend/storage/buffer/buf_table.c217
-rw-r--r--src/backend/storage/buffer/bufmgr.c2695
-rw-r--r--src/backend/storage/buffer/freelist.c373
-rw-r--r--src/backend/storage/buffer/localbuf.c370
-rw-r--r--src/backend/storage/file/fd.c1177
-rw-r--r--src/backend/storage/ipc/ipc.c991
-rw-r--r--src/backend/storage/ipc/ipci.c178
-rw-r--r--src/backend/storage/ipc/s_lock.c384
-rw-r--r--src/backend/storage/ipc/shmem.c951
-rw-r--r--src/backend/storage/ipc/shmqueue.c274
-rw-r--r--src/backend/storage/ipc/sinval.c222
-rw-r--r--src/backend/storage/ipc/sinvaladt.c1129
-rw-r--r--src/backend/storage/ipc/spin.c246
-rw-r--r--src/backend/storage/large_object/inv_api.c1877
-rw-r--r--src/backend/storage/lmgr/lmgr.c1129
-rw-r--r--src/backend/storage/lmgr/lock.c2137
-rw-r--r--src/backend/storage/lmgr/multi.c615
-rw-r--r--src/backend/storage/lmgr/proc.c1117
-rw-r--r--src/backend/storage/lmgr/single.c93
-rw-r--r--src/backend/storage/page/bufpage.c670
-rw-r--r--src/backend/storage/page/itemptr.c25
-rw-r--r--src/backend/storage/smgr/md.c1088
-rw-r--r--src/backend/storage/smgr/mm.c761
-rw-r--r--src/backend/storage/smgr/smgr.c432
-rw-r--r--src/backend/storage/smgr/smgrtype.c66
-rw-r--r--src/backend/tcop/aclchk.c952
-rw-r--r--src/backend/tcop/dest.c502
-rw-r--r--src/backend/tcop/fastpath.c520
-rw-r--r--src/backend/tcop/postgres.c2789
-rw-r--r--src/backend/tcop/pquery.c563
-rw-r--r--src/backend/tcop/utility.c1212
-rw-r--r--src/backend/tcop/variable.c598
-rw-r--r--src/backend/tioga/Arr_TgRecipe.h68
-rw-r--r--src/backend/tioga/Varray.c54
-rw-r--r--src/backend/tioga/Varray.h33
-rw-r--r--src/backend/tioga/tgRecipe.c1172
-rw-r--r--src/backend/tioga/tgRecipe.h181
-rw-r--r--src/backend/utils/adt/acl.c979
-rw-r--r--src/backend/utils/adt/arrayfuncs.c2706
-rw-r--r--src/backend/utils/adt/arrayutils.c123
-rw-r--r--src/backend/utils/adt/bool.c58
-rw-r--r--src/backend/utils/adt/cash.c734
-rw-r--r--src/backend/utils/adt/char.c518
-rw-r--r--src/backend/utils/adt/chunk.c989
-rw-r--r--src/backend/utils/adt/date.c1421
-rw-r--r--src/backend/utils/adt/datetime.c667
-rw-r--r--src/backend/utils/adt/datum.c221
-rw-r--r--src/backend/utils/adt/dt.c6008
-rw-r--r--src/backend/utils/adt/filename.c187
-rw-r--r--src/backend/utils/adt/float.c2140
-rw-r--r--src/backend/utils/adt/geo_ops.c5111
-rw-r--r--src/backend/utils/adt/geo_selfuncs.c142
-rw-r--r--src/backend/utils/adt/int.c641
-rw-r--r--src/backend/utils/adt/like.c287
-rw-r--r--src/backend/utils/adt/misc.c73
-rw-r--r--src/backend/utils/adt/nabstime.c682
-rw-r--r--src/backend/utils/adt/name.c242
-rw-r--r--src/backend/utils/adt/not_in.c148
-rw-r--r--src/backend/utils/adt/numutils.c687
-rw-r--r--src/backend/utils/adt/oid.c153
-rw-r--r--src/backend/utils/adt/oidint2.c110
-rw-r--r--src/backend/utils/adt/oidint4.c139
-rw-r--r--src/backend/utils/adt/oidname.c115
-rw-r--r--src/backend/utils/adt/oracle_compat.c714
-rw-r--r--src/backend/utils/adt/regexp.c398
-rw-r--r--src/backend/utils/adt/regproc.c229
-rw-r--r--src/backend/utils/adt/selfuncs.c962
-rw-r--r--src/backend/utils/adt/sets.c260
-rw-r--r--src/backend/utils/adt/tid.c109
-rw-r--r--src/backend/utils/adt/timestamp.c126
-rw-r--r--src/backend/utils/adt/varchar.c738
-rw-r--r--src/backend/utils/adt/varlena.c819
-rw-r--r--src/backend/utils/cache/catcache.c1786
-rw-r--r--src/backend/utils/cache/fcache.c481
-rw-r--r--src/backend/utils/cache/inval.c840
-rw-r--r--src/backend/utils/cache/lsyscache.c618
-rw-r--r--src/backend/utils/cache/rel.c57
-rw-r--r--src/backend/utils/cache/relcache.c3493
-rw-r--r--src/backend/utils/cache/syscache.c1057
-rw-r--r--src/backend/utils/error/assert.c86
-rw-r--r--src/backend/utils/error/elog.c392
-rw-r--r--src/backend/utils/error/exc.c229
-rw-r--r--src/backend/utils/error/excabort.c20
-rw-r--r--src/backend/utils/error/excid.c40
-rw-r--r--src/backend/utils/error/format.c30
-rw-r--r--src/backend/utils/fmgr/dfmgr.c441
-rw-r--r--src/backend/utils/fmgr/fmgr.c390
-rw-r--r--src/backend/utils/hash/dynahash.c1382
-rw-r--r--src/backend/utils/hash/hashfn.c212
-rw-r--r--src/backend/utils/init/enbl.c21
-rw-r--r--src/backend/utils/init/findbe.c377
-rw-r--r--src/backend/utils/init/globals.c127
-rw-r--r--src/backend/utils/init/miscinit.c268
-rw-r--r--src/backend/utils/init/postinit.c1064
-rw-r--r--src/backend/utils/misc/superuser.c28
-rw-r--r--src/backend/utils/mmgr/aset.c411
-rw-r--r--src/backend/utils/mmgr/mcxt.c517
-rw-r--r--src/backend/utils/mmgr/oset.c126
-rw-r--r--src/backend/utils/mmgr/palloc.c82
-rw-r--r--src/backend/utils/mmgr/portalmem.c1222
-rw-r--r--src/backend/utils/sort/lselect.c525
-rw-r--r--src/backend/utils/sort/psort.c1311
-rw-r--r--src/backend/utils/time/tqual.c1263
-rw-r--r--src/bin/pg_dump/common.c589
-rw-r--r--src/bin/pg_dump/pg_dump.c4050
-rw-r--r--src/bin/pg_dump/pg_dump.h368
-rw-r--r--src/bin/pg_id/pg_id.c62
-rw-r--r--src/bin/pg_passwd/pg_passwd.c553
-rw-r--r--src/bin/pg_version/pg_version.c41
-rw-r--r--src/bin/pgtclsh/pgtclAppInit.c111
-rw-r--r--src/bin/pgtclsh/pgtkAppInit.c117
-rw-r--r--src/bin/psql/psql.c3771
-rw-r--r--src/bin/psql/psqlHelp.h338
-rw-r--r--src/bin/psql/stringutils.c116
-rw-r--r--src/bin/psql/stringutils.h11
-rw-r--r--src/include/access/attnum.h34
-rw-r--r--src/include/access/funcindex.h21
-rw-r--r--src/include/access/genam.h58
-rw-r--r--src/include/access/gist.h231
-rw-r--r--src/include/access/gistscan.h19
-rw-r--r--src/include/access/giststrat.h9
-rw-r--r--src/include/access/hash.h384
-rw-r--r--src/include/access/heapam.h228
-rw-r--r--src/include/access/hio.h15
-rw-r--r--src/include/access/htup.h101
-rw-r--r--src/include/access/ibit.h25
-rw-r--r--src/include/access/iqual.h15
-rw-r--r--src/include/access/istrat.h62
-rw-r--r--src/include/access/itup.h98
-rw-r--r--src/include/access/nbtree.h388
-rw-r--r--src/include/access/printtup.h20
-rw-r--r--src/include/access/relscan.h92
-rw-r--r--src/include/access/rtree.h167
-rw-r--r--src/include/access/rtscan.h8
-rw-r--r--src/include/access/rtstrat.h11
-rw-r--r--src/include/access/sdir.h35
-rw-r--r--src/include/access/skey.h48
-rw-r--r--src/include/access/strat.h99
-rw-r--r--src/include/access/transam.h212
-rw-r--r--src/include/access/tupdesc.h81
-rw-r--r--src/include/access/tupmacs.h20
-rw-r--r--src/include/access/valid.h24
-rw-r--r--src/include/access/xact.h112
-rw-r--r--src/include/bootstrap/bootstrap.h64
-rw-r--r--src/include/c.h537
-rw-r--r--src/include/catalog/catalog.h16
-rw-r--r--src/include/catalog/catname.h10
-rw-r--r--src/include/catalog/heap.h25
-rw-r--r--src/include/catalog/index.h69
-rw-r--r--src/include/catalog/indexing.h110
-rw-r--r--src/include/catalog/pg_aggregate.h175
-rw-r--r--src/include/catalog/pg_am.h133
-rw-r--r--src/include/catalog/pg_amop.h215
-rw-r--r--src/include/catalog/pg_amproc.h61
-rw-r--r--src/include/catalog/pg_attrdef.h47
-rw-r--r--src/include/catalog/pg_attribute.h917
-rw-r--r--src/include/catalog/pg_class.h248
-rw-r--r--src/include/catalog/pg_database.h49
-rw-r--r--src/include/catalog/pg_defaults.h45
-rw-r--r--src/include/catalog/pg_demon.h57
-rw-r--r--src/include/catalog/pg_group.h30
-rw-r--r--src/include/catalog/pg_hosts.h36
-rw-r--r--src/include/catalog/pg_index.h93
-rw-r--r--src/include/catalog/pg_inheritproc.h47
-rw-r--r--src/include/catalog/pg_inherits.h49
-rw-r--r--src/include/catalog/pg_ipl.h47
-rw-r--r--src/include/catalog/pg_language.h52
-rw-r--r--src/include/catalog/pg_listener.h41
-rw-r--r--src/include/catalog/pg_log.h33
-rw-r--r--src/include/catalog/pg_magic.h45
-rw-r--r--src/include/catalog/pg_opclass.h103
-rw-r--r--src/include/catalog/pg_operator.h1104
-rw-r--r--src/include/catalog/pg_parg.h55
-rw-r--r--src/include/catalog/pg_proc.h1886
-rw-r--r--src/include/catalog/pg_relcheck.h47
-rw-r--r--src/include/catalog/pg_rewrite.h63
-rw-r--r--src/include/catalog/pg_server.h49
-rw-r--r--src/include/catalog/pg_statistic.h57
-rw-r--r--src/include/catalog/pg_time.h31
-rw-r--r--src/include/catalog/pg_trigger.h92
-rw-r--r--src/include/catalog/pg_type.h455
-rw-r--r--src/include/catalog/pg_user.h63
-rw-r--r--src/include/catalog/pg_variable.h33
-rw-r--r--src/include/catalog/pg_version.h49
-rw-r--r--src/include/commands/async.h20
-rw-r--r--src/include/commands/cluster.h16
-rw-r--r--src/include/commands/command.h30
-rw-r--r--src/include/commands/copy.h13
-rw-r--r--src/include/commands/creatinh.h12
-rw-r--r--src/include/commands/defrem.h47
-rw-r--r--src/include/commands/explain.h12
-rw-r--r--src/include/commands/purge.h17
-rw-r--r--src/include/commands/recipe.h8
-rw-r--r--src/include/commands/rename.h24
-rw-r--r--src/include/commands/sequence.h36
-rw-r--r--src/include/commands/trigger.h79
-rw-r--r--src/include/commands/vacuum.h169
-rw-r--r--src/include/commands/version.h8
-rw-r--r--src/include/commands/view.h16
-rw-r--r--src/include/executor/execFlatten.h13
-rw-r--r--src/include/executor/execdebug.h360
-rw-r--r--src/include/executor/execdefs.h44
-rw-r--r--src/include/executor/execdesc.h32
-rw-r--r--src/include/executor/executor.h189
-rw-r--r--src/include/executor/functions.h18
-rw-r--r--src/include/executor/hashjoin.h97
-rw-r--r--src/include/executor/nodeAgg.h18
-rw-r--r--src/include/executor/nodeAppend.h18
-rw-r--r--src/include/executor/nodeGroup.h18
-rw-r--r--src/include/executor/nodeHash.h41
-rw-r--r--src/include/executor/nodeHashjoin.h23
-rw-r--r--src/include/executor/nodeIndexscan.h29
-rw-r--r--src/include/executor/nodeMaterial.h22
-rw-r--r--src/include/executor/nodeMergejoin.h18
-rw-r--r--src/include/executor/nodeNestloop.h18
-rw-r--r--src/include/executor/nodeResult.h18
-rw-r--r--src/include/executor/nodeSeqscan.h24
-rw-r--r--src/include/executor/nodeSort.h22
-rw-r--r--src/include/executor/nodeTee.h20
-rw-r--r--src/include/executor/nodeUnique.h18
-rw-r--r--src/include/executor/spi.h81
-rw-r--r--src/include/executor/tuptable.h76
-rw-r--r--src/include/lib/dllist.h98
-rw-r--r--src/include/lib/fstack.h96
-rw-r--r--src/include/lib/hasht.h14
-rw-r--r--src/include/lib/lispsort.h10
-rw-r--r--src/include/lib/qsort.h20
-rw-r--r--src/include/lib/stringinfo.h31
-rw-r--r--src/include/libpq/auth.h38
-rw-r--r--src/include/libpq/be-fsstubs.h36
-rw-r--r--src/include/libpq/hba.h48
-rw-r--r--src/include/libpq/libpq-be.h36
-rw-r--r--src/include/libpq/libpq-fs.h109
-rw-r--r--src/include/libpq/libpq.h328
-rw-r--r--src/include/libpq/password.h5
-rw-r--r--src/include/libpq/pqcomm.h173
-rw-r--r--src/include/libpq/pqsignal.h12
-rw-r--r--src/include/miscadmin.h177
-rw-r--r--src/include/nodes/execnodes.h1022
-rw-r--r--src/include/nodes/makefuncs.h60
-rw-r--r--src/include/nodes/memnodes.h117
-rw-r--r--src/include/nodes/nodeFuncs.h16
-rw-r--r--src/include/nodes/nodes.h450
-rw-r--r--src/include/nodes/params.h103
-rw-r--r--src/include/nodes/parsenodes.h1148
-rw-r--r--src/include/nodes/pg_list.h144
-rw-r--r--src/include/nodes/plannodes.h375
-rw-r--r--src/include/nodes/primnodes.h448
-rw-r--r--src/include/nodes/print.h27
-rw-r--r--src/include/nodes/readfuncs.h20
-rw-r--r--src/include/nodes/relation.h466
-rw-r--r--src/include/optimizer/clauseinfo.h22
-rw-r--r--src/include/optimizer/clauses.h74
-rw-r--r--src/include/optimizer/cost.h77
-rw-r--r--src/include/optimizer/geqo.h55
-rw-r--r--src/include/optimizer/geqo_copy.h18
-rw-r--r--src/include/optimizer/geqo_gene.h44
-rw-r--r--src/include/optimizer/geqo_misc.h28
-rw-r--r--src/include/optimizer/geqo_mutation.h18
-rw-r--r--src/include/optimizer/geqo_paths.h20
-rw-r--r--src/include/optimizer/geqo_pool.h28
-rw-r--r--src/include/optimizer/geqo_random.h18
-rw-r--r--src/include/optimizer/geqo_recombination.h66
-rw-r--r--src/include/optimizer/geqo_selection.h18
-rw-r--r--src/include/optimizer/internal.h81
-rw-r--r--src/include/optimizer/joininfo.h12
-rw-r--r--src/include/optimizer/keys.h14
-rw-r--r--src/include/optimizer/ordering.h22
-rw-r--r--src/include/optimizer/pathnode.h53
-rw-r--r--src/include/optimizer/paths.h92
-rw-r--r--src/include/optimizer/plancat.h73
-rw-r--r--src/include/optimizer/planmain.h60
-rw-r--r--src/include/optimizer/planner.h10
-rw-r--r--src/include/optimizer/prep.h43
-rw-r--r--src/include/optimizer/tlist.h40
-rw-r--r--src/include/optimizer/var.h14
-rw-r--r--src/include/optimizer/xfunc.h81
-rw-r--r--src/include/parser/catalog_utils.h71
-rw-r--r--src/include/parser/dbcommands.h21
-rw-r--r--src/include/parser/gramparse.h14
-rw-r--r--src/include/parser/keywords.h23
-rw-r--r--src/include/parser/parse_query.h81
-rw-r--r--src/include/parser/parse_state.h31
-rw-r--r--src/include/parser/parsetree.h73
-rw-r--r--src/include/parser/scansup.h9
-rw-r--r--src/include/parser/sysfunc.h9
-rw-r--r--src/include/port/BSD44_derived.h30
-rw-r--r--src/include/port/aix.h18
-rw-r--r--src/include/port/alpha.h14
-rw-r--r--src/include/port/bsdi.h18
-rw-r--r--src/include/port/dgux.h17
-rw-r--r--src/include/port/hpux.h28
-rw-r--r--src/include/port/i386_solaris.h54
-rw-r--r--src/include/port/irix5.h14
-rw-r--r--src/include/port/linux.h59
-rw-r--r--src/include/port/nextstep.h36
-rw-r--r--src/include/port/sco.h8
-rw-r--r--src/include/port/sparc_solaris.h28
-rw-r--r--src/include/port/sunos4.h16
-rw-r--r--src/include/port/svr4.h16
-rw-r--r--src/include/port/ultrix4.h79
-rw-r--r--src/include/port/univel.h38
-rw-r--r--src/include/port/win32.h16
-rw-r--r--src/include/postgres.h197
-rw-r--r--src/include/postgres_ext.h30
-rw-r--r--src/include/regex/cclass.h105
-rw-r--r--src/include/regex/cdefs.h112
-rw-r--r--src/include/regex/cname.h417
-rw-r--r--src/include/regex/regex.h123
-rw-r--r--src/include/regex/regex2.h195
-rw-r--r--src/include/regex/regexp.h56
-rw-r--r--src/include/regex/utils.h34
-rw-r--r--src/include/rewrite/locks.h15
-rw-r--r--src/include/rewrite/prs2lock.h40
-rw-r--r--src/include/rewrite/rewriteDefine.h12
-rw-r--r--src/include/rewrite/rewriteHandler.h35
-rw-r--r--src/include/rewrite/rewriteManip.h35
-rw-r--r--src/include/rewrite/rewriteRemove.h16
-rw-r--r--src/include/rewrite/rewriteSupport.h22
-rw-r--r--src/include/storage/backendid.h23
-rw-r--r--src/include/storage/block.h65
-rw-r--r--src/include/storage/buf.h20
-rw-r--r--src/include/storage/buf_internals.h262
-rw-r--r--src/include/storage/bufmgr.h89
-rw-r--r--src/include/storage/bufpage.h196
-rw-r--r--src/include/storage/fd.h74
-rw-r--r--src/include/storage/ipc.h242
-rw-r--r--src/include/storage/item.h10
-rw-r--r--src/include/storage/itemid.h53
-rw-r--r--src/include/storage/itempos.h39
-rw-r--r--src/include/storage/itemptr.h80
-rw-r--r--src/include/storage/large_object.h60
-rw-r--r--src/include/storage/lmgr.h92
-rw-r--r--src/include/storage/lock.h170
-rw-r--r--src/include/storage/multilev.h38
-rw-r--r--src/include/storage/off.h40
-rw-r--r--src/include/storage/page.h14
-rw-r--r--src/include/storage/pagenum.h14
-rw-r--r--src/include/storage/pos.h32
-rw-r--r--src/include/storage/proc.h113
-rw-r--r--src/include/storage/shmem.h86
-rw-r--r--src/include/storage/sinval.h23
-rw-r--r--src/include/storage/sinvaladt.h176
-rw-r--r--src/include/storage/smgr.h124
-rw-r--r--src/include/storage/spin.h20
-rw-r--r--src/include/strdup.h2
-rw-r--r--src/include/tcop/dest.h88
-rw-r--r--src/include/tcop/fastpath.h22
-rw-r--r--src/include/tcop/pquery.h22
-rw-r--r--src/include/tcop/tcopdebug.h22
-rw-r--r--src/include/tcop/tcopprot.h35
-rw-r--r--src/include/tcop/utility.h8
-rw-r--r--src/include/tcop/variable.h25
-rw-r--r--src/include/utils/acl.h197
-rw-r--r--src/include/utils/array.h162
-rw-r--r--src/include/utils/bit.h24
-rw-r--r--src/include/utils/builtins.h817
-rw-r--r--src/include/utils/cash.h34
-rw-r--r--src/include/utils/catcache.h98
-rw-r--r--src/include/utils/datetime.h6
-rw-r--r--src/include/utils/datum.h19
-rw-r--r--src/include/utils/dt.h373
-rw-r--r--src/include/utils/dynahash.h11
-rw-r--r--src/include/utils/dynamic_loader.h31
-rw-r--r--src/include/utils/elog.h38
-rw-r--r--src/include/utils/exc.h107
-rw-r--r--src/include/utils/excid.h16
-rw-r--r--src/include/utils/fcache.h80
-rw-r--r--src/include/utils/fcache2.h8
-rw-r--r--src/include/utils/fmgrtab.h25
-rw-r--r--src/include/utils/geo_decls.h513
-rw-r--r--src/include/utils/hsearch.h190
-rw-r--r--src/include/utils/inval.h37
-rw-r--r--src/include/utils/lselect.h62
-rw-r--r--src/include/utils/lsyscache.h46
-rw-r--r--src/include/utils/mcxt.h39
-rw-r--r--src/include/utils/memutils.h271
-rw-r--r--src/include/utils/module.h18
-rw-r--r--src/include/utils/nabstime.h96
-rw-r--r--src/include/utils/oidcompos.h68
-rw-r--r--src/include/utils/palloc.h17
-rw-r--r--src/include/utils/portal.h85
-rw-r--r--src/include/utils/psort.h104
-rw-r--r--src/include/utils/rel.h155
-rw-r--r--src/include/utils/rel2.h15
-rw-r--r--src/include/utils/relcache.h26
-rw-r--r--src/include/utils/sets.h10
-rw-r--r--src/include/utils/syscache.h129
-rw-r--r--src/include/utils/tqual.h36
-rw-r--r--src/include/version.h16
-rw-r--r--src/interfaces/libpgtcl/libpgtcl.h12
-rw-r--r--src/interfaces/libpgtcl/pgtcl.c277
-rw-r--r--src/interfaces/libpgtcl/pgtclCmds.c2054
-rw-r--r--src/interfaces/libpgtcl/pgtclCmds.h134
-rw-r--r--src/interfaces/libpgtcl/pgtclId.c260
-rw-r--r--src/interfaces/libpgtcl/pgtclId.h24
-rw-r--r--src/interfaces/libpq/fe-auth.c763
-rw-r--r--src/interfaces/libpq/fe-auth.h34
-rw-r--r--src/interfaces/libpq/fe-connect.c1686
-rw-r--r--src/interfaces/libpq/fe-connect.h12
-rw-r--r--src/interfaces/libpq/fe-exec.c3014
-rw-r--r--src/interfaces/libpq/fe-lobj.c939
-rw-r--r--src/interfaces/libpq/fe-misc.c227
-rw-r--r--src/interfaces/libpq/libpq-fe.h503
-rw-r--r--src/interfaces/libpq/pqsignal.c38
-rw-r--r--src/interfaces/libpq/pqsignal.h12
-rw-r--r--src/lextest/lextest.c6
-rw-r--r--src/test/examples/testlibpq.c213
-rw-r--r--src/test/examples/testlibpq2.c142
-rw-r--r--src/test/examples/testlibpq3.c263
-rw-r--r--src/test/examples/testlibpq4.c240
-rw-r--r--src/test/examples/testlo.c392
-rw-r--r--src/test/examples/testlo2.c378
-rw-r--r--src/test/regress/regress.c375
-rw-r--r--src/tools/entab/entab.c153
-rw-r--r--src/tools/entab/halt.c54
-rw-r--r--src/tutorial/C-code/beard.c68
-rw-r--r--src/tutorial/C-code/complex.c175
-rw-r--r--src/tutorial/C-code/funcs.c89
-rw-r--r--src/utils/strdup.c14
-rw-r--r--src/utils/version.c190
687 files changed, 152157 insertions, 138270 deletions
diff --git a/contrib/array/array_iterator.c b/contrib/array/array_iterator.c
index 95ab119f85..c0c61f0b6a 100644
--- a/contrib/array/array_iterator.c
+++ b/contrib/array/array_iterator.c
@@ -8,8 +8,8 @@
* For example array_int4eq returns true if some of the elements
* of an array of int4 is equal to the given value:
*
- * array_int4eq({1,2,3}, 1) --> true
- * array_int4eq({1,2,3}, 4) --> false
+ * array_int4eq({1,2,3}, 1) --> true
+ * array_int4eq({1,2,3}, 4) --> false
*
* If we have defined T array types and O scalar operators
* we can define T x O array operators, each of them has a name
@@ -19,10 +19,10 @@
* the array_int4_like because there is no like operator for int4.
* It is now possible to write queries which look inside the arrays:
*
- * create table t(id int4[], txt text[]);
- * select * from t where t.id *= 123;
- * select * from t where t.txt *~ '[a-z]';
- * select * from t where t.txt[1:3] **~ '[a-z]';
+ * create table t(id int4[], txt text[]);
+ * select * from t where t.id *= 123;
+ * select * from t where t.txt *~ '[a-z]';
+ * select * from t where t.txt[1:3] **~ '[a-z]';
*
* Copyright (c) 1996, Massimo Dal Zotto <[email protected]>
*/
@@ -40,93 +40,116 @@
#include "utils/builtins.h"
#include "utils/elog.h"
-static int32
-array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
+static int32
+array_iterator(Oid elemtype, Oid proc, int and, ArrayType * array, Datum value)
{
- HeapTuple typ_tuple;
- TypeTupleForm typ_struct;
- bool typbyval;
- int typlen;
- func_ptr proc_fn;
- int pronargs;
- int nitems, i, result;
- int ndim, *dim;
- char *p;
-
- /* Sanity checks */
- if ((array == (ArrayType *) NULL)
- || (ARR_IS_LO(array) == true)) {
- /* elog(NOTICE, "array_iterator: array is null"); */
- return (0);
- }
- ndim = ARR_NDIM(array);
- dim = ARR_DIMS(array);
- nitems = getNitems(ndim, dim);
- if (nitems == 0) {
- /* elog(NOTICE, "array_iterator: nitems = 0"); */
- return (0);
- }
-
- /* Lookup element type information */
- typ_tuple = SearchSysCacheTuple(TYPOID, ObjectIdGetDatum(elemtype),0,0,0);
- if (!HeapTupleIsValid(typ_tuple)) {
- elog(WARN,"array_iterator: cache lookup failed for type %d", elemtype);
- return 0;
- }
- typ_struct = (TypeTupleForm) GETSTRUCT(typ_tuple);
- typlen = typ_struct->typlen;
- typbyval = typ_struct->typbyval;
-
- /* Lookup the function entry point */
- proc_fn == (func_ptr) NULL;
- fmgr_info(proc, &proc_fn, &pronargs);
- if ((proc_fn == NULL) || (pronargs != 2)) {
- elog(WARN, "array_iterator: fmgr_info lookup failed for oid %d", proc);
- return (0);
- }
-
- /* Scan the array and apply the operator to each element */
- result = 0;
- p = ARR_DATA_PTR(array);
- for (i = 0; i < nitems; i++) {
- if (typbyval) {
- switch(typlen) {
- case 1:
- result = (int) (*proc_fn)(*p, value);
- break;
- case 2:
- result = (int) (*proc_fn)(* (int16 *) p, value);
- break;
- case 3:
- case 4:
- result = (int) (*proc_fn)(* (int32 *) p, value);
- break;
- }
- p += typlen;
- } else {
- result = (int) (*proc_fn)(p, value);
- if (typlen > 0) {
- p += typlen;
- } else {
- p += INTALIGN(* (int32 *) p);
- }
- }
- if (result) {
- if (!and) {
- return (1);
- }
- } else {
- if (and) {
+ HeapTuple typ_tuple;
+ TypeTupleForm typ_struct;
+ bool typbyval;
+ int typlen;
+ func_ptr proc_fn;
+ int pronargs;
+ int nitems,
+ i,
+ result;
+ int ndim,
+ *dim;
+ char *p;
+
+ /* Sanity checks */
+ if ((array == (ArrayType *) NULL)
+ || (ARR_IS_LO(array) == true))
+ {
+ /* elog(NOTICE, "array_iterator: array is null"); */
+ return (0);
+ }
+ ndim = ARR_NDIM(array);
+ dim = ARR_DIMS(array);
+ nitems = getNitems(ndim, dim);
+ if (nitems == 0)
+ {
+ /* elog(NOTICE, "array_iterator: nitems = 0"); */
return (0);
- }
}
- }
- if (and && result) {
- return (1);
- } else {
- return (0);
- }
+ /* Lookup element type information */
+ typ_tuple = SearchSysCacheTuple(TYPOID, ObjectIdGetDatum(elemtype), 0, 0, 0);
+ if (!HeapTupleIsValid(typ_tuple))
+ {
+ elog(WARN, "array_iterator: cache lookup failed for type %d", elemtype);
+ return 0;
+ }
+ typ_struct = (TypeTupleForm) GETSTRUCT(typ_tuple);
+ typlen = typ_struct->typlen;
+ typbyval = typ_struct->typbyval;
+
+ /* Lookup the function entry point */
+ proc_fn == (func_ptr) NULL;
+ fmgr_info(proc, &proc_fn, &pronargs);
+ if ((proc_fn == NULL) || (pronargs != 2))
+ {
+ elog(WARN, "array_iterator: fmgr_info lookup failed for oid %d", proc);
+ return (0);
+ }
+
+ /* Scan the array and apply the operator to each element */
+ result = 0;
+ p = ARR_DATA_PTR(array);
+ for (i = 0; i < nitems; i++)
+ {
+ if (typbyval)
+ {
+ switch (typlen)
+ {
+ case 1:
+ result = (int) (*proc_fn) (*p, value);
+ break;
+ case 2:
+ result = (int) (*proc_fn) (*(int16 *) p, value);
+ break;
+ case 3:
+ case 4:
+ result = (int) (*proc_fn) (*(int32 *) p, value);
+ break;
+ }
+ p += typlen;
+ }
+ else
+ {
+ result = (int) (*proc_fn) (p, value);
+ if (typlen > 0)
+ {
+ p += typlen;
+ }
+ else
+ {
+ p += INTALIGN(*(int32 *) p);
+ }
+ }
+ if (result)
+ {
+ if (!and)
+ {
+ return (1);
+ }
+ }
+ else
+ {
+ if (and)
+ {
+ return (0);
+ }
+ }
+ }
+
+ if (and && result)
+ {
+ return (1);
+ }
+ else
+ {
+ return (0);
+ }
}
/*
@@ -134,39 +157,39 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
*/
int32
-array_texteq(ArrayType *array, char* value)
+array_texteq(ArrayType * array, char *value)
{
- return array_iterator((Oid) 25, /* text */
- (Oid) 67, /* texteq */
- 0, /* logical or */
- array, (Datum)value);
+ return array_iterator((Oid) 25, /* text */
+ (Oid) 67, /* texteq */
+ 0, /* logical or */
+ array, (Datum) value);
}
int32
-array_all_texteq(ArrayType *array, char* value)
+array_all_texteq(ArrayType * array, char *value)
{
- return array_iterator((Oid) 25, /* text */
- (Oid) 67, /* texteq */
- 1, /* logical and */
- array, (Datum)value);
+ return array_iterator((Oid) 25, /* text */
+ (Oid) 67, /* texteq */
+ 1, /* logical and */
+ array, (Datum) value);
}
int32
-array_textregexeq(ArrayType *array, char* value)
+array_textregexeq(ArrayType * array, char *value)
{
- return array_iterator((Oid) 25, /* text */
- (Oid) 81, /* textregexeq */
- 0, /* logical or */
- array, (Datum)value);
+ return array_iterator((Oid) 25, /* text */
+ (Oid) 81, /* textregexeq */
+ 0, /* logical or */
+ array, (Datum) value);
}
int32
-array_all_textregexeq(ArrayType *array, char* value)
+array_all_textregexeq(ArrayType * array, char *value)
{
- return array_iterator((Oid) 25, /* text */
- (Oid) 81, /* textregexeq */
- 1, /* logical and */
- array, (Datum)value);
+ return array_iterator((Oid) 25, /* text */
+ (Oid) 81, /* textregexeq */
+ 1, /* logical and */
+ array, (Datum) value);
}
/*
@@ -175,39 +198,39 @@ array_all_textregexeq(ArrayType *array, char* value)
*/
int32
-array_char16eq(ArrayType *array, char* value)
+array_char16eq(ArrayType * array, char *value)
{
- return array_iterator((Oid) 20, /* char16 */
- (Oid) 490, /* char16eq */
- 0, /* logical or */
- array, (Datum)value);
+ return array_iterator((Oid) 20, /* char16 */
+ (Oid) 490, /* char16eq */
+ 0, /* logical or */
+ array, (Datum) value);
}
int32
-array_all_char16eq(ArrayType *array, char* value)
+array_all_char16eq(ArrayType * array, char *value)
{
- return array_iterator((Oid) 20, /* char16 */
- (Oid) 490, /* char16eq */
- 1, /* logical and */
- array, (Datum)value);
+ return array_iterator((Oid) 20, /* char16 */
+ (Oid) 490, /* char16eq */
+ 1, /* logical and */
+ array, (Datum) value);
}
int32
-array_char16regexeq(ArrayType *array, char* value)
+array_char16regexeq(ArrayType * array, char *value)
{
- return array_iterator((Oid) 20, /* char16 */
- (Oid) 700, /* char16regexeq */
- 0, /* logical or */
- array, (Datum)value);
+ return array_iterator((Oid) 20, /* char16 */
+ (Oid) 700, /* char16regexeq */
+ 0, /* logical or */
+ array, (Datum) value);
}
int32
-array_all_char16regexeq(ArrayType *array, char* value)
+array_all_char16regexeq(ArrayType * array, char *value)
{
- return array_iterator((Oid) 20, /* char16 */
- (Oid) 700, /* char16regexeq */
- 1, /* logical and */
- array, (Datum)value);
+ return array_iterator((Oid) 20, /* char16 */
+ (Oid) 700, /* char16regexeq */
+ 1, /* logical and */
+ array, (Datum) value);
}
/*
@@ -215,37 +238,37 @@ array_all_char16regexeq(ArrayType *array, char* value)
*/
int32
-array_int4eq(ArrayType *array, int4 value)
+array_int4eq(ArrayType * array, int4 value)
{
- return array_iterator((Oid) 23, /* int4 */
- (Oid) 65, /* int4eq */
- 0, /* logical or */
- array, (Datum)value);
+ return array_iterator((Oid) 23, /* int4 */
+ (Oid) 65, /* int4eq */
+ 0, /* logical or */
+ array, (Datum) value);
}
int32
-array_all_int4eq(ArrayType *array, int4 value)
+array_all_int4eq(ArrayType * array, int4 value)
{
- return array_iterator((Oid) 23, /* int4 */
- (Oid) 65, /* int4eq */
- 1, /* logical and */
- array, (Datum)value);
+ return array_iterator((Oid) 23, /* int4 */
+ (Oid) 65, /* int4eq */
+ 1, /* logical and */
+ array, (Datum) value);
}
int32
-array_int4gt(ArrayType *array, int4 value)
+array_int4gt(ArrayType * array, int4 value)
{
- return array_iterator((Oid) 23, /* int4 */
- (Oid) 147, /* int4gt */
- 0, /* logical or */
- array, (Datum)value);
+ return array_iterator((Oid) 23, /* int4 */
+ (Oid) 147, /* int4gt */
+ 0, /* logical or */
+ array, (Datum) value);
}
int32
-array_all_int4gt(ArrayType *array, int4 value)
+array_all_int4gt(ArrayType * array, int4 value)
{
- return array_iterator((Oid) 23, /* int4 */
- (Oid) 147, /* int4gt */
- 1, /* logical and */
- array, (Datum)value);
+ return array_iterator((Oid) 23, /* int4 */
+ (Oid) 147, /* int4gt */
+ 1, /* logical and */
+ array, (Datum) value);
}
diff --git a/contrib/datetime/datetime_functions.c b/contrib/datetime/datetime_functions.c
index e684ce5826..08e7250700 100644
--- a/contrib/datetime/datetime_functions.c
+++ b/contrib/datetime/datetime_functions.c
@@ -13,86 +13,99 @@
#include "utils/datetime.h"
-TimeADT *time_difference(TimeADT * time1, TimeADT * time2)
+TimeADT *
+time_difference(TimeADT * time1, TimeADT * time2)
{
- TimeADT *result = (TimeADT *) palloc(sizeof(TimeADT));
- *result = *time1 - *time2;
- return (result);
+ TimeADT *result = (TimeADT *) palloc(sizeof(TimeADT));
+
+ *result = *time1 - *time2;
+ return (result);
}
-TimeADT *currenttime()
+TimeADT *
+currenttime()
{
- time_t current_time;
- struct tm *tm;
- TimeADT *result = (TimeADT *) palloc(sizeof(TimeADT));
-
- current_time = time(NULL);
- tm = localtime(&current_time);
- *result = ((((tm->tm_hour*60)+tm->tm_min)*60)+tm->tm_sec);
- return (result);
+ time_t current_time;
+ struct tm *tm;
+ TimeADT *result = (TimeADT *) palloc(sizeof(TimeADT));
+
+ current_time = time(NULL);
+ tm = localtime(&current_time);
+ *result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec);
+ return (result);
}
-DateADT currentdate()
+DateADT
+currentdate()
{
- time_t current_time;
- struct tm *tm;
- DateADT result;
- current_time = time(NULL);
- tm = localtime(&current_time);
-
- result = date2j(tm->tm_year,tm->tm_mon + 1,tm->tm_mday) -
- date2j(100,1,1);
- return (result);
+ time_t current_time;
+ struct tm *tm;
+ DateADT result;
+
+ current_time = time(NULL);
+ tm = localtime(&current_time);
+
+ result = date2j(tm->tm_year, tm->tm_mon + 1, tm->tm_mday) -
+ date2j(100, 1, 1);
+ return (result);
}
-int4 hours(TimeADT * time)
+int4
+hours(TimeADT * time)
{
- return(*time / (60*60));
+ return (*time / (60 * 60));
}
-int4 minutes(TimeADT * time)
+int4
+minutes(TimeADT * time)
{
- return(((int) (*time / 60)) % 60);
+ return (((int) (*time / 60)) % 60);
}
-int4 seconds(TimeADT * time)
+int4
+seconds(TimeADT * time)
{
- return(((int) *time) % 60);
+ return (((int) *time) % 60);
}
-int4 day(DateADT *date)
+int4
+day(DateADT * date)
{
- struct tm tm;
+ struct tm tm;
- j2date( (*date + date2j(2000,1,1)),
- &tm.tm_year, &tm.tm_mon, &tm.tm_mday);
+ j2date((*date + date2j(2000, 1, 1)),
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday);
- return (tm.tm_mday);
+ return (tm.tm_mday);
}
-int4 month(DateADT *date)
+int4
+month(DateADT * date)
{
- struct tm tm;
+ struct tm tm;
- j2date( (*date + date2j(2000,1,1)),
- &tm.tm_year, &tm.tm_mon, &tm.tm_mday);
+ j2date((*date + date2j(2000, 1, 1)),
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday);
- return (tm.tm_mon);
+ return (tm.tm_mon);
}
-int4 year(DateADT *date)
+int4
+year(DateADT * date)
{
- struct tm tm;
+ struct tm tm;
- j2date( (*date + date2j(2000,1,1)),
- &tm.tm_year, &tm.tm_mon, &tm.tm_mday);
+ j2date((*date + date2j(2000, 1, 1)),
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday);
- return (tm.tm_year);
+ return (tm.tm_year);
}
-int4 asminutes(TimeADT * time)
+int4
+asminutes(TimeADT * time)
{
- int seconds = (int) *time;
+ int seconds = (int) *time;
- return (seconds / 60);
+ return (seconds / 60);
}
-int4 asseconds(TimeADT * time)
+int4
+asseconds(TimeADT * time)
{
- int seconds = (int) *time;
+ int seconds = (int) *time;
- return (seconds);
+ return (seconds);
}
diff --git a/contrib/int8/int8.c b/contrib/int8/int8.c
index 93822cb480..a73986beeb 100644
--- a/contrib/int8/int8.c
+++ b/contrib/int8/int8.c
@@ -1,12 +1,12 @@
/*-------------------------------------------------------------------------
*
* int8.c--
- * Internal 64-bit integer operations
+ * Internal 64-bit integer operations
*
*-------------------------------------------------------------------------
*/
-#include <stdio.h> /* for sprintf proto, etc. */
-#include <stdlib.h> /* for strtod, etc. */
+#include <stdio.h> /* for sprintf proto, etc. */
+#include <stdlib.h> /* for strtod, etc. */
#include <string.h>
#include <ctype.h>
#include <time.h>
@@ -17,7 +17,7 @@
#include "postgres.h"
#include "utils/palloc.h"
-#define MAXINT8LEN 25
+#define MAXINT8LEN 25
#define USE_LOCAL_CODE 1
@@ -26,53 +26,58 @@
#endif
#ifndef HAVE_64BIT_INTS
-typedef char[8] int64;
+typedef char [8] int64;
#elif defined(__alpha)
typedef long int int64;
+
#define INT64_FORMAT "%ld"
#elif defined(__GNUC__)
typedef long long int int64;
+
#define INT64_FORMAT "%Ld"
#else
typedef long int int64;
+
#define INT64_FORMAT "%ld"
#endif
-int64 *int8in(char *str);
-char *int8out(int64 *val);
-
-bool int8eq(int64 *val1, int64 *val2);
-bool int8ne(int64 *val1, int64 *val2);
-bool int8lt(int64 *val1, int64 *val2);
-bool int8gt(int64 *val1, int64 *val2);
-bool int8le(int64 *val1, int64 *val2);
-bool int8ge(int64 *val1, int64 *val2);
-
-bool int84eq(int64 *val1, int32 val2);
-bool int84ne(int64 *val1, int32 val2);
-bool int84lt(int64 *val1, int32 val2);
-bool int84gt(int64 *val1, int32 val2);
-bool int84le(int64 *val1, int32 val2);
-bool int84ge(int64 *val1, int32 val2);
-
-int64 *int8um(int64 *val);
-int64 *int8pl(int64 *val1, int64 *val2);
-int64 *int8mi(int64 *val1, int64 *val2);
-int64 *int8mul(int64 *val1, int64 *val2);
-int64 *int8div(int64 *val1, int64 *val2);
-
-int64 *int48(int32 val);
-int32 int84(int64 *val);
+int64 *int8in(char *str);
+char *int8out(int64 * val);
+
+bool int8eq(int64 * val1, int64 * val2);
+bool int8ne(int64 * val1, int64 * val2);
+bool int8lt(int64 * val1, int64 * val2);
+bool int8gt(int64 * val1, int64 * val2);
+bool int8le(int64 * val1, int64 * val2);
+bool int8ge(int64 * val1, int64 * val2);
+
+bool int84eq(int64 * val1, int32 val2);
+bool int84ne(int64 * val1, int32 val2);
+bool int84lt(int64 * val1, int32 val2);
+bool int84gt(int64 * val1, int32 val2);
+bool int84le(int64 * val1, int32 val2);
+bool int84ge(int64 * val1, int32 val2);
+
+int64 *int8um(int64 * val);
+int64 *int8pl(int64 * val1, int64 * val2);
+int64 *int8mi(int64 * val1, int64 * val2);
+int64 *int8mul(int64 * val1, int64 * val2);
+int64 *int8div(int64 * val1, int64 * val2);
+
+int64 *int48(int32 val);
+int32 int84(int64 * val);
+
#if FALSE
-int64 *int28(int16 val);
-int16 int82(int64 *val);
+int64 *int28(int16 val);
+int16 int82(int64 * val);
+
#endif
-float64 i8tod(int64 *val);
-int64 *dtoi8(float64 val);
+float64 i8tod(int64 * val);
+int64 *dtoi8(float64 val);
#if USE_LOCAL_CODE
@@ -88,7 +93,7 @@ int64 *dtoi8(float64 val);
/***********************************************************************
**
- ** Routines for 64-bit integers.
+ ** Routines for 64-bit integers.
**
***********************************************************************/
@@ -98,264 +103,289 @@ int64 *dtoi8(float64 val);
/* int8in()
*/
-int64 *int8in(char *str)
+int64 *
+int8in(char *str)
{
- int64 *result = PALLOCTYPE(int64);
+ int64 *result = PALLOCTYPE(int64);
#if HAVE_64BIT_INTS
- if (!PointerIsValid(str))
- elog (WARN,"Bad (null) int8 external representation",NULL);
+ if (!PointerIsValid(str))
+ elog(WARN, "Bad (null) int8 external representation", NULL);
- if (sscanf(str, INT64_FORMAT, result) != 1)
- elog(WARN,"Bad int8 external representation '%s'",str);
+ if (sscanf(str, INT64_FORMAT, result) != 1)
+ elog(WARN, "Bad int8 external representation '%s'", str);
#else
- elog(WARN,"64-bit integers are not supported",NULL);
- result = NULL;
+ elog(WARN, "64-bit integers are not supported", NULL);
+ result = NULL;
#endif
- return(result);
-} /* int8in() */
+ return (result);
+} /* int8in() */
/* int8out()
*/
-char *int8out(int64 *val)
+char *
+int8out(int64 * val)
{
- char *result;
+ char *result;
- int len;
- char buf[MAXINT8LEN+1];
+ int len;
+ char buf[MAXINT8LEN + 1];
#if HAVE_64BIT_INTS
- if (!PointerIsValid(val))
- return(NULL);
+ if (!PointerIsValid(val))
+ return (NULL);
- if ((len = snprintf( buf, MAXINT8LEN, INT64_FORMAT, *val)) < 0)
- elog (WARN,"Unable to format int8",NULL);
+ if ((len = snprintf(buf, MAXINT8LEN, INT64_FORMAT, *val)) < 0)
+ elog(WARN, "Unable to format int8", NULL);
- result = PALLOC(len+1);
+ result = PALLOC(len + 1);
- strcpy(result, buf);
+ strcpy(result, buf);
#else
- elog(WARN,"64-bit integers are not supported",NULL);
- result = NULL;
+ elog(WARN, "64-bit integers are not supported", NULL);
+ result = NULL;
#endif
- return( result);
-} /* int8out() */
+ return (result);
+} /* int8out() */
/*----------------------------------------------------------
- * Relational operators for int8s.
+ * Relational operators for int8s.
*---------------------------------------------------------*/
/* int8relop()
* Is val1 relop val2?
*/
-bool int8eq(int64 *val1, int64 *val2)
+bool
+int8eq(int64 * val1, int64 * val2)
{
- return(*val1 == *val2);
-} /* int8eq() */
+ return (*val1 == *val2);
+} /* int8eq() */
-bool int8ne(int64 *val1, int64 *val2)
+bool
+int8ne(int64 * val1, int64 * val2)
{
- return(*val1 != *val2);
-} /* int8ne() */
+ return (*val1 != *val2);
+} /* int8ne() */
-bool int8lt(int64 *val1, int64 *val2)
+bool
+int8lt(int64 * val1, int64 * val2)
{
- return(*val1 < *val2);
-} /* int8lt() */
+ return (*val1 < *val2);
+} /* int8lt() */
-bool int8gt(int64 *val1, int64 *val2)
+bool
+int8gt(int64 * val1, int64 * val2)
{
- return(*val1 > *val2);
-} /* int8gt() */
+ return (*val1 > *val2);
+} /* int8gt() */
-bool int8le(int64 *val1, int64 *val2)
+bool
+int8le(int64 * val1, int64 * val2)
{
- return(*val1 <= *val2);
-} /* int8le() */
+ return (*val1 <= *val2);
+} /* int8le() */
-bool int8ge(int64 *val1, int64 *val2)
+bool
+int8ge(int64 * val1, int64 * val2)
{
- return(*val1 >= *val2);
-} /* int8ge() */
+ return (*val1 >= *val2);
+} /* int8ge() */
/* int84relop()
* Is 64-bit val1 relop 32-bit val2?
*/
-bool int84eq(int64 *val1, int32 val2)
+bool
+int84eq(int64 * val1, int32 val2)
{
- return(*val1 == val2);
-} /* int84eq() */
+ return (*val1 == val2);
+} /* int84eq() */
-bool int84ne(int64 *val1, int32 val2)
+bool
+int84ne(int64 * val1, int32 val2)
{
- return(*val1 != val2);
-} /* int84ne() */
+ return (*val1 != val2);
+} /* int84ne() */
-bool int84lt(int64 *val1, int32 val2)
+bool
+int84lt(int64 * val1, int32 val2)
{
- return(*val1 < val2);
-} /* int84lt() */
+ return (*val1 < val2);
+} /* int84lt() */
-bool int84gt(int64 *val1, int32 val2)
+bool
+int84gt(int64 * val1, int32 val2)
{
- return(*val1 > val2);
-} /* int84gt() */
+ return (*val1 > val2);
+} /* int84gt() */
-bool int84le(int64 *val1, int32 val2)
+bool
+int84le(int64 * val1, int32 val2)
{
- return(*val1 <= val2);
-} /* int84le() */
+ return (*val1 <= val2);
+} /* int84le() */
-bool int84ge(int64 *val1, int32 val2)
+bool
+int84ge(int64 * val1, int32 val2)
{
- return(*val1 >= val2);
-} /* int84ge() */
+ return (*val1 >= val2);
+} /* int84ge() */
/*----------------------------------------------------------
- * Arithmetic operators on 64-bit integers.
+ * Arithmetic operators on 64-bit integers.
*---------------------------------------------------------*/
-int64 *int8um(int64 *val)
+int64 *
+int8um(int64 * val)
{
- int64 *result = PALLOCTYPE(int64);
+ int64 *result = PALLOCTYPE(int64);
- if (!PointerIsValid(val))
- return NULL;
+ if (!PointerIsValid(val))
+ return NULL;
- *result = (- *val);
+ *result = (-*val);
- return(result);
-} /* int8um() */
+ return (result);
+} /* int8um() */
-int64 *int8pl(int64 *val1, int64 *val2)
+int64 *
+int8pl(int64 * val1, int64 * val2)
{
- int64 *result = PALLOCTYPE(int64);
+ int64 *result = PALLOCTYPE(int64);
- if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
- return NULL;
+ if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
+ return NULL;
- *result = *val1 + *val2;
+ *result = *val1 + *val2;
- return(result);
-} /* int8pl() */
+ return (result);
+} /* int8pl() */
-int64 *int8mi(int64 *val1, int64 *val2)
+int64 *
+int8mi(int64 * val1, int64 * val2)
{
- int64 *result = PALLOCTYPE(int64);
+ int64 *result = PALLOCTYPE(int64);
- if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
- return NULL;
+ if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
+ return NULL;
- *result = *val1 - *val2;
+ *result = *val1 - *val2;
- return(result);
-} /* int8mi() */
+ return (result);
+} /* int8mi() */
-int64 *int8mul(int64 *val1, int64 *val2)
+int64 *
+int8mul(int64 * val1, int64 * val2)
{
- int64 *result = PALLOCTYPE(int64);
+ int64 *result = PALLOCTYPE(int64);
- if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
- return NULL;
+ if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
+ return NULL;
- *result = *val1 * *val2;
+ *result = *val1 * *val2;
- return(result);
-} /* int8mul() */
+ return (result);
+} /* int8mul() */
-int64 *int8div(int64 *val1, int64 *val2)
+int64 *
+int8div(int64 * val1, int64 * val2)
{
- int64 *result = PALLOCTYPE(int64);
+ int64 *result = PALLOCTYPE(int64);
- if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
- return NULL;
+ if ((!PointerIsValid(val1)) || (!PointerIsValid(val2)))
+ return NULL;
- *result = *val1 / *val2;
+ *result = *val1 / *val2;
- return(result);
-} /* int8div() */
+ return (result);
+} /* int8div() */
/*----------------------------------------------------------
- * Conversion operators.
+ * Conversion operators.
*---------------------------------------------------------*/
-int64 *int48(int32 val)
+int64 *
+int48(int32 val)
{
- int64 *result = PALLOCTYPE(int64);
+ int64 *result = PALLOCTYPE(int64);
- *result = val;
+ *result = val;
- return(result);
-} /* int48() */
+ return (result);
+} /* int48() */
-int32 int84(int64 *val)
+int32
+int84(int64 * val)
{
- int32 result;
+ int32 result;
- if (!PointerIsValid(val))
- elog(WARN,"Invalid (null) int64, can't convert int8 to int4",NULL);
+ if (!PointerIsValid(val))
+ elog(WARN, "Invalid (null) int64, can't convert int8 to int4", NULL);
- if ((*val < INT_MIN) || (*val > INT_MAX))
- elog(WARN,"int8 conversion to int4 is out of range",NULL);
+ if ((*val < INT_MIN) || (*val > INT_MAX))
+ elog(WARN, "int8 conversion to int4 is out of range", NULL);
- result = *val;
+ result = *val;
- return(result);
-} /* int84() */
+ return (result);
+} /* int84() */
#if FALSE
-int64 *int28(int16 val)
+int64 *
+int28(int16 val)
{
- int64 *result;
+ int64 *result;
- if (!PointerIsValid(result = PALLOCTYPE(int64)))
- elog(WARN,"Memory allocation failed, can't convert int8 to int2",NULL);
+ if (!PointerIsValid(result = PALLOCTYPE(int64)))
+ elog(WARN, "Memory allocation failed, can't convert int8 to int2", NULL);
- *result = val;
+ *result = val;
- return(result);
-} /* int28() */
+ return (result);
+} /* int28() */
-int16 int82(int64 *val)
+int16
+int82(int64 * val)
{
- int16 result;
+ int16 result;
- if (!PointerIsValid(val))
- elog(WARN,"Invalid (null) int8, can't convert to int2",NULL);
+ if (!PointerIsValid(val))
+ elog(WARN, "Invalid (null) int8, can't convert to int2", NULL);
- result = *val;
+ result = *val;
+
+ return (result);
+} /* int82() */
- return(result);
-} /* int82() */
#endif
-float64 i8tod(int64 *val)
+float64
+i8tod(int64 * val)
{
- float64 result = PALLOCTYPE(float64data);
+ float64 result = PALLOCTYPE(float64data);
- *result = *val;
+ *result = *val;
- return(result);
-} /* i8tod() */
+ return (result);
+} /* i8tod() */
-int64 *dtoi8(float64 val)
+int64 *
+dtoi8(float64 val)
{
- int64 *result = PALLOCTYPE(int64);
-
- if ((*val < (-pow(2,64)+1)) || (*val > (pow(2,64)-1)))
- elog(WARN,"Floating point conversion to int64 is out of range",NULL);
+ int64 *result = PALLOCTYPE(int64);
- *result = *val;
+ if ((*val < (-pow(2, 64) + 1)) || (*val > (pow(2, 64) - 1)))
+ elog(WARN, "Floating point conversion to int64 is out of range", NULL);
- return(result);
-} /* dtoi8() */
+ *result = *val;
+ return (result);
+} /* dtoi8() */
diff --git a/contrib/pginterface/halt.c b/contrib/pginterface/halt.c
index 58ca11a587..000e4a9c40 100644
--- a/contrib/pginterface/halt.c
+++ b/contrib/pginterface/halt.c
@@ -1,8 +1,8 @@
/*
**
-** halt.c
+** halt.c
**
-** This is used to print out error messages and exit
+** This is used to print out error messages and exit
*/
#include <varargs.h>
@@ -15,44 +15,46 @@
/*-------------------------------------------------------------------------
**
-** halt - print error message, and call clean up routine or exit
+** halt - print error message, and call clean up routine or exit
**
**------------------------------------------------------------------------*/
/*VARARGS*/
-void halt(va_alist)
+void
+halt(va_alist)
va_dcl
{
- va_list arg_ptr;
- char *format, *pstr;
- void (*sig_func)();
+ va_list arg_ptr;
+ char *format,
+ *pstr;
+ void (*sig_func) ();
va_start(arg_ptr);
- format = va_arg(arg_ptr,char *);
- if (strncmp(format,"PERROR", 6) != 0)
- vfprintf(stderr,format,arg_ptr);
+ format = va_arg(arg_ptr, char *);
+ if (strncmp(format, "PERROR", 6) != 0)
+ vfprintf(stderr, format, arg_ptr);
else
{
- for (pstr=format+6; *pstr == ' ' || *pstr == ':'; pstr++)
+ for (pstr = format + 6; *pstr == ' ' || *pstr == ':'; pstr++)
;
- vfprintf(stderr,pstr,arg_ptr);
+ vfprintf(stderr, pstr, arg_ptr);
perror("");
- }
+ }
va_end(arg_ptr);
fflush(stderr);
- /* call one clean up function if defined */
- if ( (sig_func = signal(SIGTERM, SIG_DFL)) != SIG_DFL &&
- sig_func != SIG_IGN)
- (*sig_func)(0);
- else if ( (sig_func = signal(SIGHUP, SIG_DFL)) != SIG_DFL &&
- sig_func != SIG_IGN)
- (*sig_func)(0);
- else if ( (sig_func = signal(SIGINT, SIG_DFL)) != SIG_DFL &&
- sig_func != SIG_IGN)
- (*sig_func)(0);
- else if ( (sig_func = signal(SIGQUIT, SIG_DFL)) != SIG_DFL &&
- sig_func != SIG_IGN)
- (*sig_func)(0);
+ /* call one clean up function if defined */
+ if ((sig_func = signal(SIGTERM, SIG_DFL)) != SIG_DFL &&
+ sig_func != SIG_IGN)
+ (*sig_func) (0);
+ else if ((sig_func = signal(SIGHUP, SIG_DFL)) != SIG_DFL &&
+ sig_func != SIG_IGN)
+ (*sig_func) (0);
+ else if ((sig_func = signal(SIGINT, SIG_DFL)) != SIG_DFL &&
+ sig_func != SIG_IGN)
+ (*sig_func) (0);
+ else if ((sig_func = signal(SIGQUIT, SIG_DFL)) != SIG_DFL &&
+ sig_func != SIG_IGN)
+ (*sig_func) (0);
exit(1);
}
diff --git a/contrib/pginterface/halt.h b/contrib/pginterface/halt.h
index cb4ea545b9..8e1af05e4c 100644
--- a/contrib/pginterface/halt.h
+++ b/contrib/pginterface/halt.h
@@ -3,5 +3,4 @@
**
*/
-void halt();
-
+void halt();
diff --git a/contrib/pginterface/pginsert.c b/contrib/pginterface/pginsert.c
index 92c869b383..9946b258ff 100644
--- a/contrib/pginterface/pginsert.c
+++ b/contrib/pginterface/pginsert.c
@@ -10,20 +10,25 @@
#include "halt.h"
#include "pginterface.h"
-int main(int argc, char **argv)
+int
+main(int argc, char **argv)
{
- char query[4000];
- int row =1;
- int aint;
- float afloat;
- double adouble;
- char achar[11], achar16[17], abpchar[11], avarchar[51], atext[51];
- time_t aabstime;
-
+ char query[4000];
+ int row = 1;
+ int aint;
+ float afloat;
+ double adouble;
+ char achar[11],
+ achar16[17],
+ abpchar[11],
+ avarchar[51],
+ atext[51];
+ time_t aabstime;
+
if (argc != 2)
- halt("Usage: %s database\n",argv[0]);
+ halt("Usage: %s database\n", argv[0]);
- connectdb(argv[1],NULL,NULL,NULL,NULL);
+ connectdb(argv[1], NULL, NULL, NULL, NULL);
on_error_continue();
doquery("DROP TABLE testfetch");
@@ -42,9 +47,9 @@ int main(int argc, char **argv)
aabstime abstime) \
");
- while(1)
+ while (1)
{
- sprintf(query,"INSERT INTO testfetch VALUES ( \
+ sprintf(query, "INSERT INTO testfetch VALUES ( \
%d, \
2322.12, \
'923121.0323'::float8, \
@@ -55,44 +60,43 @@ int main(int argc, char **argv)
'Ernie', \
'now' )", row);
doquery(query);
-
+
doquery("BEGIN WORK");
- doquery("DECLARE c_testfetch BINARY CURSOR FOR \
+ doquery("DECLARE c_testfetch BINARY CURSOR FOR \
SELECT * FROM testfetch");
doquery("FETCH ALL IN c_testfetch");
while (fetch(
- &aint,
- &afloat,
- &adouble,
- achar,
- achar16,
- abpchar,
- avarchar,
- atext,
- &aabstime) != END_OF_TUPLES)
- printf("int %d\nfloat %f\ndouble %f\nchar %s\nchar16 %s\n\
+ &aint,
+ &afloat,
+ &adouble,
+ achar,
+ achar16,
+ abpchar,
+ avarchar,
+ atext,
+ &aabstime) != END_OF_TUPLES)
+ printf("int %d\nfloat %f\ndouble %f\nchar %s\nchar16 %s\n\
bpchar %s\nvarchar %s\ntext %s\nabstime %s",
- aint,
- afloat,
- adouble,
- achar,
- achar16,
- abpchar,
- avarchar,
- atext,
- ctime(&aabstime));
+ aint,
+ afloat,
+ adouble,
+ achar,
+ achar16,
+ abpchar,
+ avarchar,
+ atext,
+ ctime(&aabstime));
+
-
doquery("CLOSE c_testfetch");
doquery("COMMIT WORK");
- printf("--- %-d rows inserted so far\n",row);
-
+ printf("--- %-d rows inserted so far\n", row);
+
row++;
}
disconnectdb();
return 0;
}
-
diff --git a/contrib/pginterface/pginterface.c b/contrib/pginterface/pginterface.c
index 7593cd9f97..f1ade9dcd4 100644
--- a/contrib/pginterface/pginterface.c
+++ b/contrib/pginterface/pginterface.c
@@ -12,77 +12,82 @@
#include "halt.h"
#include "pginterface.h"
-static void sig_disconnect();
-static void set_signals();
+static void sig_disconnect();
+static void set_signals();
#define NUL '\0'
/* GLOBAL VARIABLES */
-static PGconn* conn;
-static PGresult* res = NULL;
+static PGconn *conn;
+static PGresult *res = NULL;
#define ON_ERROR_STOP 0
-#define ON_ERROR_CONTINUE 1
+#define ON_ERROR_CONTINUE 1
-static int on_error_state = ON_ERROR_STOP;
+static int on_error_state = ON_ERROR_STOP;
/* LOCAL VARIABLES */
-static sigset_t block_sigs, unblock_sigs;
-static int tuple;
+static sigset_t block_sigs,
+ unblock_sigs;
+static int tuple;
/*
**
-** connectdb - returns PGconn structure
+** connectdb - returns PGconn structure
**
*/
-PGconn *connectdb( char *dbName,
- char *pghost,
- char *pgport,
- char *pgoptions,
- char *pgtty)
+PGconn *
+connectdb(char *dbName,
+ char *pghost,
+ char *pgport,
+ char *pgoptions,
+ char *pgtty)
{
/* make a connection to the database */
conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);
if (PQstatus(conn) == CONNECTION_BAD)
halt("Connection to database '%s' failed.\n%s\n", dbName,
- PQerrorMessage(conn));
+ PQerrorMessage(conn));
set_signals();
return conn;
}
/*
**
-** disconnectdb
+** disconnectdb
**
*/
-void disconnectdb()
+void
+disconnectdb()
{
PQfinish(conn);
}
/*
**
-** doquery - returns PGresult structure
+** doquery - returns PGresult structure
**
*/
-PGresult *doquery(char *query)
+PGresult *
+doquery(char *query)
{
if (res != NULL)
PQclear(res);
- sigprocmask(SIG_SETMASK,&block_sigs,NULL);
+ sigprocmask(SIG_SETMASK, &block_sigs, NULL);
res = PQexec(conn, query);
- sigprocmask(SIG_SETMASK,&unblock_sigs,NULL);
+ sigprocmask(SIG_SETMASK, &unblock_sigs, NULL);
if (on_error_state == ON_ERROR_STOP &&
(res == NULL ||
- PQresultStatus(res) == PGRES_BAD_RESPONSE ||
- PQresultStatus(res) == PGRES_NONFATAL_ERROR ||
- PQresultStatus(res) == PGRES_FATAL_ERROR))
+ PQresultStatus(res) == PGRES_BAD_RESPONSE ||
+ PQresultStatus(res) == PGRES_NONFATAL_ERROR ||
+ PQresultStatus(res) == PGRES_FATAL_ERROR))
{
if (res != NULL)
- fprintf(stderr,"query error: %s\n",PQcmdStatus(res));
- else fprintf(stderr,"connection error: %s\n",PQerrorMessage(conn));
+ fprintf(stderr, "query error: %s\n", PQcmdStatus(res));
+ else
+ fprintf(stderr, "connection error: %s\n", PQerrorMessage(conn));
PQfinish(conn);
halt("failed request: %s\n", query);
}
@@ -92,14 +97,16 @@ PGresult *doquery(char *query)
/*
**
-** fetch - returns tuple number (starts at 0), or the value END_OF_TUPLES
-** NULL pointers are skipped
+** fetch - returns tuple number (starts at 0), or the value END_OF_TUPLES
+** NULL pointers are skipped
**
*/
-int fetch(void *param, ...)
+int
+fetch(void *param,...)
{
- va_list ap;
- int arg, num_fields;
+ va_list ap;
+ int arg,
+ num_fields;
num_fields = PQnfields(res);
@@ -113,11 +120,11 @@ int fetch(void *param, ...)
{
if (PQfsize(res, arg) == -1)
{
- memcpy(param,PQgetvalue(res,tuple,arg),PQgetlength(res,tuple,arg));
- ((char *)param)[PQgetlength(res,tuple,arg)] = NUL;
+ memcpy(param, PQgetvalue(res, tuple, arg), PQgetlength(res, tuple, arg));
+ ((char *) param)[PQgetlength(res, tuple, arg)] = NUL;
}
else
- memcpy(param,PQgetvalue(res,tuple,arg),PQfsize(res,arg));
+ memcpy(param, PQgetvalue(res, tuple, arg), PQfsize(res, arg));
}
param = va_arg(ap, char *);
}
@@ -127,15 +134,17 @@ int fetch(void *param, ...)
/*
**
-** fetchwithnulls - returns tuple number (starts at 0),
-** or the value END_OF_TUPLES
-** Returns true or false into null indicator variables
-** NULL pointers are skipped
+** fetchwithnulls - returns tuple number (starts at 0),
+** or the value END_OF_TUPLES
+** Returns true or false into null indicator variables
+** NULL pointers are skipped
*/
-int fetchwithnulls(void *param, ...)
+int
+fetchwithnulls(void *param,...)
{
- va_list ap;
- int arg, num_fields;
+ va_list ap;
+ int arg,
+ num_fields;
num_fields = PQnfields(res);
@@ -149,17 +158,17 @@ int fetchwithnulls(void *param, ...)
{
if (PQfsize(res, arg) == -1)
{
- memcpy(param,PQgetvalue(res,tuple,arg),PQgetlength(res,tuple,arg));
- ((char *)param)[PQgetlength(res,tuple,arg)] = NUL;
+ memcpy(param, PQgetvalue(res, tuple, arg), PQgetlength(res, tuple, arg));
+ ((char *) param)[PQgetlength(res, tuple, arg)] = NUL;
}
else
- memcpy(param,PQgetvalue(res,tuple,arg),PQfsize(res,arg));
+ memcpy(param, PQgetvalue(res, tuple, arg), PQfsize(res, arg));
}
param = va_arg(ap, char *);
- if (PQgetisnull(res,tuple,arg) != 0)
- *(int *)param = 1;
+ if (PQgetisnull(res, tuple, arg) != 0)
+ *(int *) param = 1;
else
- *(int *)param = 0;
+ *(int *) param = 0;
param = va_arg(ap, char *);
}
va_end(ap);
@@ -168,52 +177,56 @@ int fetchwithnulls(void *param, ...)
/*
**
-** on_error_stop
+** on_error_stop
**
*/
-void on_error_stop()
+void
+on_error_stop()
{
on_error_state = ON_ERROR_STOP;
}
-
+
/*
**
-** on_error_continue
+** on_error_continue
**
*/
-void on_error_continue()
+void
+on_error_continue()
{
on_error_state = ON_ERROR_CONTINUE;
}
-
+
/*
**
-** sig_disconnect
+** sig_disconnect
**
*/
-static void sig_disconnect()
+static void
+sig_disconnect()
{
- fprintf(stderr,"exiting...\n");
+ fprintf(stderr, "exiting...\n");
PQfinish(conn);
exit(1);
}
/*
**
-** set_signals
+** set_signals
**
*/
-static void set_signals()
+static void
+set_signals()
{
sigemptyset(&block_sigs);
sigemptyset(&unblock_sigs);
- sigaddset(&block_sigs,SIGTERM);
- sigaddset(&block_sigs,SIGHUP);
- sigaddset(&block_sigs,SIGINT);
-/* sigaddset(&block_sigs,SIGQUIT); no block */
- sigprocmask(SIG_SETMASK,&unblock_sigs,NULL);
- signal(SIGTERM,sig_disconnect);
- signal(SIGHUP,sig_disconnect);
- signal(SIGINT,sig_disconnect);
- signal(SIGQUIT,sig_disconnect);
+ sigaddset(&block_sigs, SIGTERM);
+ sigaddset(&block_sigs, SIGHUP);
+ sigaddset(&block_sigs, SIGINT);
+/* sigaddset(&block_sigs,SIGQUIT); no block */
+ sigprocmask(SIG_SETMASK, &unblock_sigs, NULL);
+ signal(SIGTERM, sig_disconnect);
+ signal(SIGHUP, sig_disconnect);
+ signal(SIGINT, sig_disconnect);
+ signal(SIGQUIT, sig_disconnect);
}
diff --git a/contrib/pginterface/pginterface.h b/contrib/pginterface/pginterface.h
index 7e9cbdb5eb..65894eae34 100644
--- a/contrib/pginterface/pginterface.h
+++ b/contrib/pginterface/pginterface.h
@@ -3,12 +3,12 @@
*
*/
-PGresult *doquery(char *query);
-PGconn *connectdb();
-void disconnectdb();
-int fetch(void *param, ...);
-int fetchwithnulls(void *param, ...);
-void on_error_continue();
-void on_error_stop();
+PGresult *doquery(char *query);
+PGconn *connectdb();
+void disconnectdb();
+int fetch(void *param,...);
+int fetchwithnulls(void *param,...);
+void on_error_continue();
+void on_error_stop();
#define END_OF_TUPLES (-1)
diff --git a/contrib/pginterface/pgnulltest.c b/contrib/pginterface/pgnulltest.c
index 283106f726..2622edcaf6 100644
--- a/contrib/pginterface/pgnulltest.c
+++ b/contrib/pginterface/pgnulltest.c
@@ -12,29 +12,34 @@
#include <libpq-fe.h>
#include <pginterface.h>
-int main(int argc, char **argv)
+int
+main(int argc, char **argv)
{
- char query[4000];
- int row =1;
- int aint;
- float afloat;
- double adouble;
- char achar[11], achar16[17], abpchar[11], avarchar[51], atext[51];
- time_t aabstime;
- int aint_null,
- afloat_null,
- adouble_null,
- achar_null,
- achar16_null,
- abpchar_null,
- avarchar_null,
- atext_null,
- aabstime_null;
+ char query[4000];
+ int row = 1;
+ int aint;
+ float afloat;
+ double adouble;
+ char achar[11],
+ achar16[17],
+ abpchar[11],
+ avarchar[51],
+ atext[51];
+ time_t aabstime;
+ int aint_null,
+ afloat_null,
+ adouble_null,
+ achar_null,
+ achar16_null,
+ abpchar_null,
+ avarchar_null,
+ atext_null,
+ aabstime_null;
if (argc != 2)
- halt("Usage: %s database\n",argv[0]);
+ halt("Usage: %s database\n", argv[0]);
- connectdb(argv[1],NULL,NULL,NULL,NULL);
+ connectdb(argv[1], NULL, NULL, NULL, NULL);
on_error_continue();
doquery("DROP TABLE testfetch");
@@ -54,7 +59,7 @@ int main(int argc, char **argv)
");
#ifdef TEST_NON_NULLS
- sprintf(query,"INSERT INTO testfetch VALUES ( \
+ sprintf(query, "INSERT INTO testfetch VALUES ( \
0, \
0, \
0, \
@@ -65,7 +70,7 @@ int main(int argc, char **argv)
'', \
'');");
#else
- sprintf(query,"INSERT INTO testfetch VALUES ( \
+ sprintf(query, "INSERT INTO testfetch VALUES ( \
NULL, \
NULL, \
NULL, \
@@ -85,55 +90,54 @@ int main(int argc, char **argv)
doquery("FETCH ALL IN c_testfetch");
if (fetchwithnulls(
- &aint,
- &aint_null,
- &afloat,
- &afloat_null,
- &adouble,
- &adouble_null,
- achar,
- &achar_null,
- achar16,
- &achar16_null,
- abpchar,
- &abpchar_null,
- avarchar,
- &avarchar_null,
- atext,
- &atext_null,
- &aabstime,
- &aabstime_null) != END_OF_TUPLES)
- printf("int %d\nfloat %f\ndouble %f\nchar %s\nchar16 %s\n\
+ &aint,
+ &aint_null,
+ &afloat,
+ &afloat_null,
+ &adouble,
+ &adouble_null,
+ achar,
+ &achar_null,
+ achar16,
+ &achar16_null,
+ abpchar,
+ &abpchar_null,
+ avarchar,
+ &avarchar_null,
+ atext,
+ &atext_null,
+ &aabstime,
+ &aabstime_null) != END_OF_TUPLES)
+ printf("int %d\nfloat %f\ndouble %f\nchar %s\nchar16 %s\n\
bpchar %s\nvarchar %s\ntext %s\nabstime %s\n",
- aint,
- afloat,
- adouble,
- achar,
- achar16,
- abpchar,
- avarchar,
- atext,
- ctime(&aabstime));
- printf("NULL:\nint %d\nfloat %d\ndouble %d\nchar %d\nchar16 %d\n\
+ aint,
+ afloat,
+ adouble,
+ achar,
+ achar16,
+ abpchar,
+ avarchar,
+ atext,
+ ctime(&aabstime));
+ printf("NULL:\nint %d\nfloat %d\ndouble %d\nchar %d\nchar16 %d\n\
bpchar %d\nvarchar %d\ntext %d\nabstime %d\n",
- aint_null,
- afloat_null,
- adouble_null,
- achar_null,
- achar16_null,
- abpchar_null,
- avarchar_null,
- atext_null,
- aabstime_null);
+ aint_null,
+ afloat_null,
+ adouble_null,
+ achar_null,
+ achar16_null,
+ abpchar_null,
+ avarchar_null,
+ atext_null,
+ aabstime_null);
doquery("CLOSE c_testfetch");
doquery("COMMIT WORK");
- printf("--- %-d rows inserted so far\n",row);
+ printf("--- %-d rows inserted so far\n", row);
row++;
disconnectdb();
return 0;
}
-
diff --git a/contrib/pginterface/pgwordcount.c b/contrib/pginterface/pgwordcount.c
index f2d2d488fc..c447cdcaa0 100644
--- a/contrib/pginterface/pgwordcount.c
+++ b/contrib/pginterface/pgwordcount.c
@@ -10,17 +10,18 @@
#include <libpq-fe.h>
#include "pginterface.h"
-int main(int argc, char **argv)
+int
+main(int argc, char **argv)
{
- char query[4000];
- int row = 0;
- int count;
- char line[4000];
-
+ char query[4000];
+ int row = 0;
+ int count;
+ char line[4000];
+
if (argc != 2)
- halt("Usage: %s database\n",argv[0]);
+ halt("Usage: %s database\n", argv[0]);
- connectdb(argv[1],NULL,NULL,NULL,NULL);
+ connectdb(argv[1], NULL, NULL, NULL, NULL);
on_error_continue();
doquery("DROP TABLE words");
on_error_stop();
@@ -35,33 +36,33 @@ int main(int argc, char **argv)
word text_ops )\
");
- while(1)
+ while (1)
{
- if (scanf("%s",line) != 1)
+ if (scanf("%s", line) != 1)
break;
doquery("BEGIN WORK");
- sprintf(query,"\
+ sprintf(query, "\
DECLARE c_words BINARY CURSOR FOR \
SELECT count(*) \
FROM words \
WHERE word = '%s'", line);
doquery(query);
doquery("FETCH ALL IN c_words");
-
+
while (fetch(&count) == END_OF_TUPLES)
count = 0;
doquery("CLOSE c_words");
doquery("COMMIT WORK");
if (count == 0)
- sprintf(query,"\
+ sprintf(query, "\
INSERT INTO words \
- VALUES (1, '%s')", line);
+ VALUES (1, '%s')", line);
else
- sprintf(query,"\
+ sprintf(query, "\
UPDATE words \
SET matches = matches + 1 \
- WHERE word = '%s'", line);
+ WHERE word = '%s'", line);
doquery(query);
row++;
}
@@ -69,4 +70,3 @@ int main(int argc, char **argv)
disconnectdb();
return 0;
}
-
diff --git a/contrib/soundex/soundex.c b/contrib/soundex/soundex.c
index 2ce6ef510f..44ad25808d 100644
--- a/contrib/soundex/soundex.c
+++ b/contrib/soundex/soundex.c
@@ -4,80 +4,86 @@
#include <string.h>
#include <stdio.h>
-#include "postgres.h" /* for char16, etc. */
-#include "utils/palloc.h" /* for palloc */
-#include "libpq-fe.h" /* for TUPLE */
+#include "postgres.h" /* for char16, etc. */
+#include "utils/palloc.h" /* for palloc */
+#include "libpq-fe.h" /* for TUPLE */
#include <stdio.h>
#include <ctype.h>
/* prototype for soundex function */
-char *soundex(char *instr, char *outstr);
+char *soundex(char *instr, char *outstr);
-text *text_soundex(text *t)
+text *
+text_soundex(text * t)
{
- /* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
- char *table = "01230120022455012623010202";
- int count = 0;
- text *new_t;
-
- char outstr[6+1]; /* max length of soundex is 6 */
- char *instr;
-
- /* make a null-terminated string */
- instr=palloc(VARSIZE(t)+1);
- memcpy(instr,VARDATA(t),VARSIZE(t)-VARHDRSZ);
- instr[VARSIZE(t)-VARHDRSZ] = (char)0;
-
- /* load soundex into outstr */
- soundex(instr, outstr);
-
- /* Now the outstr contains the soundex of instr */
- /* copy outstr to new_t */
- new_t = (text *) palloc(strlen(outstr)+VARHDRSZ);
- memset(new_t, 0, strlen(outstr)+1);
- VARSIZE(new_t) = strlen(outstr)+VARHDRSZ;
- memcpy((void *) VARDATA(new_t),
- (void *) outstr,
- strlen(outstr));
-
- /* free instr */
- pfree(instr);
-
- return(new_t);
+ /* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
+ char *table = "01230120022455012623010202";
+ int count = 0;
+ text *new_t;
+
+ char outstr[6 + 1]; /* max length of soundex is 6 */
+ char *instr;
+
+ /* make a null-terminated string */
+ instr = palloc(VARSIZE(t) + 1);
+ memcpy(instr, VARDATA(t), VARSIZE(t) - VARHDRSZ);
+ instr[VARSIZE(t) - VARHDRSZ] = (char) 0;
+
+ /* load soundex into outstr */
+ soundex(instr, outstr);
+
+ /* Now the outstr contains the soundex of instr */
+ /* copy outstr to new_t */
+ new_t = (text *) palloc(strlen(outstr) + VARHDRSZ);
+ memset(new_t, 0, strlen(outstr) + 1);
+ VARSIZE(new_t) = strlen(outstr) + VARHDRSZ;
+ memcpy((void *) VARDATA(new_t),
+ (void *) outstr,
+ strlen(outstr));
+
+ /* free instr */
+ pfree(instr);
+
+ return (new_t);
}
-char *soundex(char *instr, char *outstr)
-{ /* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
- char *table = "01230120022455012623010202";
- int count = 0;
-
- while(!isalpha(instr[0]) && instr[0])
- ++instr;
-
- if(!instr[0]) { /* Hey! Where'd the string go? */
- outstr[0]=(char)0;
- return outstr;
- }
-
- if(toupper(instr[0]) == 'P' && toupper(instr[1]) == 'H') {
- instr[0] = 'F';
- instr[1] = 'A';
- }
-
- *outstr++ = (char)toupper(*instr++);
-
- while(*instr && count < 5) {
- if(isalpha(*instr) && *instr != *(instr-1)) {
- *outstr = table[toupper(instr[0]) - 'A'];
- if(*outstr != '0') {
- ++outstr;
- ++count;
- }
- }
- ++instr;
- }
-
- *outstr = '\0';
- return(outstr);
+char *
+soundex(char *instr, char *outstr)
+{ /* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
+ char *table = "01230120022455012623010202";
+ int count = 0;
+
+ while (!isalpha(instr[0]) && instr[0])
+ ++instr;
+
+ if (!instr[0])
+ { /* Hey! Where'd the string go? */
+ outstr[0] = (char) 0;
+ return outstr;
+ }
+
+ if (toupper(instr[0]) == 'P' && toupper(instr[1]) == 'H')
+ {
+ instr[0] = 'F';
+ instr[1] = 'A';
+ }
+
+ *outstr++ = (char) toupper(*instr++);
+
+ while (*instr && count < 5)
+ {
+ if (isalpha(*instr) && *instr != *(instr - 1))
+ {
+ *outstr = table[toupper(instr[0]) - 'A'];
+ if (*outstr != '0')
+ {
+ ++outstr;
+ ++count;
+ }
+ }
+ ++instr;
+ }
+
+ *outstr = '\0';
+ return (outstr);
}
-
diff --git a/contrib/string/string_io.c b/contrib/string/string_io.c
index b6158c74e4..e2cb2017c6 100644
--- a/contrib/string/string_io.c
+++ b/contrib/string/string_io.c
@@ -17,14 +17,14 @@
/* define this if you want to see iso-8859 characters */
#define ISO8859
-#define MIN(x, y) ((x) < (y) ? (x) : (y))
-#define VALUE(char) ((char) - '0')
-#define DIGIT(val) ((val) + '0')
-#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
+#define VALUE(char) ((char) - '0')
+#define DIGIT(val) ((val) + '0')
+#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
#ifndef ISO8859
-#define NOTPRINTABLE(c) (!isprint(c))
+#define NOTPRINTABLE(c) (!isprint(c))
#else
-#define NOTPRINTABLE(c) (!isprint(c) && ((c) < 0xa0))
+#define NOTPRINTABLE(c) (!isprint(c) && ((c) < 0xa0))
#endif
/*
@@ -36,115 +36,129 @@
* The function is used by output methods of various string types.
*
* Arguments:
- * data - input data (can be NULL)
- * size - optional size of data. A negative value indicates
- * that data is a null terminated string.
+ * data - input data (can be NULL)
+ * size - optional size of data. A negative value indicates
+ * that data is a null terminated string.
*
* Returns:
- * a pointer to a new string containing the printable
- * representation of data.
+ * a pointer to a new string containing the printable
+ * representation of data.
*/
-char *
+char *
string_output(char *data, int size)
{
- register unsigned char c, *p, *r, *result;
- register int l, len;
+ register unsigned char c,
+ *p,
+ *r,
+ *result;
+ register int l,
+ len;
+
+ if (data == NULL)
+ {
+ result = (char *) palloc(2);
+ result[0] = '-';
+ result[1] = '\0';
+ return (result);
+ }
- if (data == NULL) {
- result = (char *) palloc(2);
- result[0] = '-';
- result[1] = '\0';
- return (result);
- }
-
- if (size < 0) {
- size = strlen(data);
- }
-
- /* adjust string length for escapes */
- len = size;
- for (p=data,l=size; l>0; p++,l--) {
- switch (*p) {
- case '\\':
- case '"' :
- case '{':
- case '}':
- case '\b':
- case '\f':
- case '\n':
- case '\r':
- case '\t':
- case '\v':
- len++;
- break;
- default:
- if (NOTPRINTABLE(*p)) {
- len += 3;
- }
+ if (size < 0)
+ {
+ size = strlen(data);
+ }
+
+ /* adjust string length for escapes */
+ len = size;
+ for (p = data, l = size; l > 0; p++, l--)
+ {
+ switch (*p)
+ {
+ case '\\':
+ case '"':
+ case '{':
+ case '}':
+ case '\b':
+ case '\f':
+ case '\n':
+ case '\r':
+ case '\t':
+ case '\v':
+ len++;
+ break;
+ default:
+ if (NOTPRINTABLE(*p))
+ {
+ len += 3;
+ }
+ }
}
- }
- len++;
-
- result = (char *) palloc(len);
-
- for (p=data,r=result,l=size; (l > 0) && (c = *p); p++,l--) {
- switch (c) {
- case '\\':
- case '"' :
- case '{':
- case '}':
- *r++ = '\\';
- *r++ = c;
- break;
- case '\b':
- *r++ = '\\';
- *r++ = 'b';
- break;
- case '\f':
- *r++ = '\\';
- *r++ = 'f';
- break;
- case '\n':
- *r++ = '\\';
- *r++ = 'n';
- break;
- case '\r':
- *r++ = '\\';
- *r++ = 'r';
- break;
- case '\t':
- *r++ = '\\';
- *r++ = 't';
- break;
- case '\v':
- *r++ = '\\';
- *r++ = 'v';
- break;
- default:
- if (NOTPRINTABLE(c)) {
- *r = '\\';
- r += 3;
- *r-- = DIGIT(c & 07);
- c >>= 3;
- *r-- = DIGIT(c & 07);
- c >>= 3;
- *r = DIGIT(c & 03);
- r += 3;
- } else {
- *r++ = c;
- }
+ len++;
+
+ result = (char *) palloc(len);
+
+ for (p = data, r = result, l = size; (l > 0) && (c = *p); p++, l--)
+ {
+ switch (c)
+ {
+ case '\\':
+ case '"':
+ case '{':
+ case '}':
+ *r++ = '\\';
+ *r++ = c;
+ break;
+ case '\b':
+ *r++ = '\\';
+ *r++ = 'b';
+ break;
+ case '\f':
+ *r++ = '\\';
+ *r++ = 'f';
+ break;
+ case '\n':
+ *r++ = '\\';
+ *r++ = 'n';
+ break;
+ case '\r':
+ *r++ = '\\';
+ *r++ = 'r';
+ break;
+ case '\t':
+ *r++ = '\\';
+ *r++ = 't';
+ break;
+ case '\v':
+ *r++ = '\\';
+ *r++ = 'v';
+ break;
+ default:
+ if (NOTPRINTABLE(c))
+ {
+ *r = '\\';
+ r += 3;
+ *r-- = DIGIT(c & 07);
+ c >>= 3;
+ *r-- = DIGIT(c & 07);
+ c >>= 3;
+ *r = DIGIT(c & 03);
+ r += 3;
+ }
+ else
+ {
+ *r++ = c;
+ }
+ }
}
- }
- *r = '\0';
+ *r = '\0';
- return((char *) result);
+ return ((char *) result);
}
/*
* string_input() --
*
- * This function accepts a C string in input and copies it into a new
+ * This function accepts a C string in input and copies it into a new
* object allocated with palloc() translating all escape sequences.
* An optional header can be allocatd before the string, for example
* to hold the length of a varlena object.
@@ -153,209 +167,231 @@ string_output(char *data, int size)
* receive strings in internal form.
*
* Arguments:
- * str - input string possibly with escapes
- * size - the required size of new data. A value of 0
- * indicates a variable size string, while a
- * negative value indicates a variable size string
- * of size not greater than this absolute value.
- * hdrsize - size of an optional header to be allocated before
- * the data. It must then be filled by the caller.
- * rtn_size - an optional pointer to an int variable where the
- * size of the new string is stored back.
+ * str - input string possibly with escapes
+ * size - the required size of new data. A value of 0
+ * indicates a variable size string, while a
+ * negative value indicates a variable size string
+ * of size not greater than this absolute value.
+ * hdrsize - size of an optional header to be allocated before
+ * the data. It must then be filled by the caller.
+ * rtn_size - an optional pointer to an int variable where the
+ * size of the new string is stored back.
*
* Returns:
- * a pointer to the new string or the header.
+ * a pointer to the new string or the header.
*/
-char *
+char *
string_input(char *str, int size, int hdrsize, int *rtn_size)
{
- register unsigned char *p, *r;
- unsigned char *result;
- int len;
-
- if ((str == NULL) || (hdrsize < 0)) {
- return (char *) NULL;
- }
-
- /* Compute result size */
- len = strlen(str);
- for (p=str; *p; ) {
- if (*p++ == '\\') {
- if (ISOCTAL(*p)) {
- if (ISOCTAL(*(p+1))) {
- p++;
- len--;
- }
- if (ISOCTAL(*(p+1))) {
- p++;
- len--;
+ register unsigned char *p,
+ *r;
+ unsigned char *result;
+ int len;
+
+ if ((str == NULL) || (hdrsize < 0))
+ {
+ return (char *) NULL;
+ }
+
+ /* Compute result size */
+ len = strlen(str);
+ for (p = str; *p;)
+ {
+ if (*p++ == '\\')
+ {
+ if (ISOCTAL(*p))
+ {
+ if (ISOCTAL(*(p + 1)))
+ {
+ p++;
+ len--;
+ }
+ if (ISOCTAL(*(p + 1)))
+ {
+ p++;
+ len--;
+ }
+ }
+ if (*p)
+ p++;
+ len--;
}
- }
- if (*p) p++;
- len--;
}
- }
-
- /* result has variable length */
- if (size == 0) {
- size = len+1;
- } else
-
- /* result has variable length with maximum size */
- if (size < 0) {
- size = MIN(len, - size)+1;
- }
-
- result = (char *) palloc(hdrsize+size);
- memset(result, 0, hdrsize+size);
- if (rtn_size) {
- *rtn_size = size;
- }
-
- r = result + hdrsize;
- for (p=str; *p; ) {
- register unsigned char c;
- if ((c = *p++) == '\\') {
- switch (c = *p++) {
- case '\0':
- p--;
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- c = VALUE(c);
- if (isdigit(*p)) {
- c = (c<<3) + VALUE(*p++);
+
+ /* result has variable length */
+ if (size == 0)
+ {
+ size = len + 1;
+ }
+ else
+ /* result has variable length with maximum size */
+ if (size < 0)
+ {
+ size = MIN(len, -size) + 1;
+ }
+
+ result = (char *) palloc(hdrsize + size);
+ memset(result, 0, hdrsize + size);
+ if (rtn_size)
+ {
+ *rtn_size = size;
+ }
+
+ r = result + hdrsize;
+ for (p = str; *p;)
+ {
+ register unsigned char c;
+
+ if ((c = *p++) == '\\')
+ {
+ switch (c = *p++)
+ {
+ case '\0':
+ p--;
+ break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ c = VALUE(c);
+ if (isdigit(*p))
+ {
+ c = (c << 3) + VALUE(*p++);
+ }
+ if (isdigit(*p))
+ {
+ c = (c << 3) + VALUE(*p++);
+ }
+ *r++ = c;
+ break;
+ case 'b':
+ *r++ = '\b';
+ break;
+ case 'f':
+ *r++ = '\f';
+ break;
+ case 'n':
+ *r++ = '\n';
+ break;
+ case 'r':
+ *r++ = '\r';
+ break;
+ case 't':
+ *r++ = '\t';
+ break;
+ case 'v':
+ *r++ = '\v';
+ break;
+ default:
+ *r++ = c;
+ }
}
- if (isdigit(*p)) {
- c = (c<<3) + VALUE(*p++);
+ else
+ {
+ *r++ = c;
}
- *r++ = c;
- break;
- case 'b':
- *r++ = '\b';
- break;
- case 'f':
- *r++ = '\f';
- break;
- case 'n':
- *r++ = '\n';
- break;
- case 'r':
- *r++ = '\r';
- break;
- case 't':
- *r++ = '\t';
- break;
- case 'v':
- *r++ = '\v';
- break;
- default:
- *r++ = c;
- }
- } else {
- *r++ = c;
}
- }
- return((char *) result);
+ return ((char *) result);
}
-char *
+char *
c_charout(int32 c)
{
- char str[2];
+ char str[2];
- str[0] = (char) c;
- str[1] = '\0';
+ str[0] = (char) c;
+ str[1] = '\0';
- return (string_output(str, 1));
+ return (string_output(str, 1));
}
-char *
+char *
c_char2out(uint16 s)
{
- return (string_output((char *) &s, 2));
+ return (string_output((char *) &s, 2));
}
-char *
+char *
c_char4out(uint32 s)
{
- return (string_output((char *) &s, 4));
+ return (string_output((char *) &s, 4));
}
-char *
+char *
c_char8out(char *s)
{
- return (string_output(s, 8));
+ return (string_output(s, 8));
}
-char *
+char *
c_char16out(char *s)
{
- return (string_output(s, 16));
+ return (string_output(s, 16));
}
/*
* This can be used for text, bytea, SET and unknown data types
*/
-char *
-c_textout(struct varlena *vlena)
+char *
+c_textout(struct varlena * vlena)
{
- int len = 0;
- char *s = NULL;
-
- if (vlena) {
- len = VARSIZE(vlena) - VARHDRSZ;
- s = VARDATA(vlena);
- }
- return (string_output(s, len));
+ int len = 0;
+ char *s = NULL;
+
+ if (vlena)
+ {
+ len = VARSIZE(vlena) - VARHDRSZ;
+ s = VARDATA(vlena);
+ }
+ return (string_output(s, len));
}
/*
* This can be used for varchar and bpchar strings
*/
-char *
+char *
c_varcharout(char *s)
{
- int len;
+ int len;
- if (s) {
- len = *(int32*)s - 4;
- s += 4;
- }
- return (string_output(s, len));
+ if (s)
+ {
+ len = *(int32 *) s - 4;
+ s += 4;
+ }
+ return (string_output(s, len));
}
#ifdef 0
struct varlena *
c_textin(char *str)
{
- struct varlena *result;
- int len;
+ struct varlena *result;
+ int len;
- if (str == NULL) {
- return ((struct varlena *) NULL);
- }
+ if (str == NULL)
+ {
+ return ((struct varlena *) NULL);
+ }
- result = (struct varlena *) string_input(str, 0, VARHDRSZ, &len);
- VARSIZE(result) = len;
+ result = (struct varlena *) string_input(str, 0, VARHDRSZ, &len);
+ VARSIZE(result) = len;
- return (result);
+ return (result);
}
-char *
+char *
c_char16in(char *str)
{
- return (string_input(str, 16, 0, NULL));
+ return (string_input(str, 16, 0, NULL));
}
-#endif
+#endif
diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c
index 60ec3e4d3a..1725769030 100644
--- a/src/backend/access/common/heaptuple.c
+++ b/src/backend/access/common/heaptuple.c
@@ -1,18 +1,18 @@
/*-------------------------------------------------------------------------
*
* heaptuple.c--
- * This file contains heap tuple accessor and mutator routines, as well
- * as a few various tuple utilities.
+ * This file contains heap tuple accessor and mutator routines, as well
+ * as a few various tuple utilities.
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.21 1997/08/26 23:31:20 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.22 1997/09/07 04:37:30 momjian Exp $
*
* NOTES
- * The old interface functions have been converted to macros
- * and moved to heapam.h
+ * The old interface functions have been converted to macros
+ * and moved to heapam.h
*
*-------------------------------------------------------------------------
*/
@@ -27,9 +27,9 @@
#include <utils/memutils.h>
#ifndef HAVE_MEMMOVE
-# include <regex/utils.h>
+#include <regex/utils.h>
#else
-# include <string.h>
+#include <string.h>
#endif
@@ -37,902 +37,991 @@
#if !defined(NO_ASSERT_CHECKING) && defined(sparc) && defined(sunos4)
#define register
-#endif /* !NO_ASSERT_CHECKING && sparc && sunos4 */
+#endif /* !NO_ASSERT_CHECKING && sparc && sunos4 */
/* ----------------------------------------------------------------
- * misc support routines
+ * misc support routines
* ----------------------------------------------------------------
*/
/* ----------------
- * ComputeDataSize
+ * ComputeDataSize
* ----------------
*/
Size
ComputeDataSize(TupleDesc tupleDesc,
- Datum value[],
- char nulls[])
+ Datum value[],
+ char nulls[])
{
- uint32 data_length;
- int i;
- int numberOfAttributes = tupleDesc->natts;
- AttributeTupleForm *att = tupleDesc->attrs;
-
- for (data_length = 0, i = 0; i < numberOfAttributes; i++) {
- if (nulls[i] != ' ') continue;
-
- switch (att[i]->attlen) {
- case -1:
- /*
- * This is the size of the disk representation and so
- * must include the additional sizeof long.
- */
- if (att[i]->attalign == 'd') {
- data_length = DOUBLEALIGN(data_length)
- + VARSIZE(DatumGetPointer(value[i]));
- } else {
- data_length = INTALIGN(data_length)
- + VARSIZE(DatumGetPointer(value[i]));
- }
- break;
- case sizeof(char):
- data_length++;
- break;
- case sizeof(short):
- data_length = SHORTALIGN(data_length + sizeof(short));
- break;
- case sizeof(int32):
- data_length = INTALIGN(data_length + sizeof(int32));
- break;
- default:
- if (att[i]->attlen < sizeof(int32))
- elog(WARN, "ComputeDataSize: attribute %d has len %d",
- i, att[i]->attlen);
- if (att[i]->attalign == 'd')
- data_length = DOUBLEALIGN(data_length) + att[i]->attlen;
- else
- data_length = LONGALIGN(data_length) + att[i]->attlen;
- break;
+ uint32 data_length;
+ int i;
+ int numberOfAttributes = tupleDesc->natts;
+ AttributeTupleForm *att = tupleDesc->attrs;
+
+ for (data_length = 0, i = 0; i < numberOfAttributes; i++)
+ {
+ if (nulls[i] != ' ')
+ continue;
+
+ switch (att[i]->attlen)
+ {
+ case -1:
+
+ /*
+ * This is the size of the disk representation and so must
+ * include the additional sizeof long.
+ */
+ if (att[i]->attalign == 'd')
+ {
+ data_length = DOUBLEALIGN(data_length)
+ + VARSIZE(DatumGetPointer(value[i]));
+ }
+ else
+ {
+ data_length = INTALIGN(data_length)
+ + VARSIZE(DatumGetPointer(value[i]));
+ }
+ break;
+ case sizeof(char):
+ data_length++;
+ break;
+ case sizeof(short):
+ data_length = SHORTALIGN(data_length + sizeof(short));
+ break;
+ case sizeof(int32):
+ data_length = INTALIGN(data_length + sizeof(int32));
+ break;
+ default:
+ if (att[i]->attlen < sizeof(int32))
+ elog(WARN, "ComputeDataSize: attribute %d has len %d",
+ i, att[i]->attlen);
+ if (att[i]->attalign == 'd')
+ data_length = DOUBLEALIGN(data_length) + att[i]->attlen;
+ else
+ data_length = LONGALIGN(data_length) + att[i]->attlen;
+ break;
+ }
}
- }
-
- return data_length;
+
+ return data_length;
}
/* ----------------
- * DataFill
+ * DataFill
* ----------------
*/
void
DataFill(char *data,
- TupleDesc tupleDesc,
- Datum value[],
- char nulls[],
- char *infomask,
- bits8 *bit)
+ TupleDesc tupleDesc,
+ Datum value[],
+ char nulls[],
+ char *infomask,
+ bits8 * bit)
{
- bits8 *bitP = 0;
- int bitmask = 0;
- uint32 data_length;
- int i;
- int numberOfAttributes = tupleDesc->natts;
- AttributeTupleForm *att = tupleDesc->attrs;
-
- if (bit != NULL) {
- bitP = &bit[-1];
- bitmask = CSIGNBIT;
- }
-
- *infomask = 0;
-
- for (i = 0; i < numberOfAttributes; i++) {
- if (bit != NULL) {
- if (bitmask != CSIGNBIT) {
- bitmask <<= 1;
- } else {
- bitP += 1;
- *bitP = 0x0;
- bitmask = 1;
- }
-
- if (nulls[i] == 'n') {
- *infomask |= HEAP_HASNULL;
- continue;
- }
-
- *bitP |= bitmask;
+ bits8 *bitP = 0;
+ int bitmask = 0;
+ uint32 data_length;
+ int i;
+ int numberOfAttributes = tupleDesc->natts;
+ AttributeTupleForm *att = tupleDesc->attrs;
+
+ if (bit != NULL)
+ {
+ bitP = &bit[-1];
+ bitmask = CSIGNBIT;
}
-
- switch (att[i]->attlen) {
- case -1:
- *infomask |= HEAP_HASVARLENA;
- if (att[i]->attalign=='d') {
- data = (char *) DOUBLEALIGN(data);
- } else {
- data = (char *) INTALIGN(data);
- }
- data_length = VARSIZE(DatumGetPointer(value[i]));
- memmove(data, DatumGetPointer(value[i]),data_length);
- data += data_length;
- break;
- case sizeof(char):
- *data = att[i]->attbyval ?
- DatumGetChar(value[i]) : *((char *) value[i]);
- data += sizeof(char);
- break;
- case sizeof(int16):
- data = (char *) SHORTALIGN(data);
- * (short *) data = (att[i]->attbyval ?
- DatumGetInt16(value[i]) :
- *((short *) value[i]));
- data += sizeof(short);
- break;
- case sizeof(int32):
- data = (char *) INTALIGN(data);
- * (int32 *) data = (att[i]->attbyval ?
- DatumGetInt32(value[i]) :
- *((int32 *) value[i]));
- data += sizeof(int32);
- break;
- default:
- if (att[i]->attlen < sizeof(int32))
- elog(WARN, "DataFill: attribute %d has len %d",
- i, att[i]->attlen);
- if (att[i]->attalign == 'd') {
- data = (char *) DOUBLEALIGN(data);
- memmove(data, DatumGetPointer(value[i]),
- att[i]->attlen);
- data += att[i]->attlen;
- } else {
- data = (char *) LONGALIGN(data);
- memmove(data, DatumGetPointer(value[i]),
- att[i]->attlen);
- data += att[i]->attlen;
- }
- break;
+
+ *infomask = 0;
+
+ for (i = 0; i < numberOfAttributes; i++)
+ {
+ if (bit != NULL)
+ {
+ if (bitmask != CSIGNBIT)
+ {
+ bitmask <<= 1;
+ }
+ else
+ {
+ bitP += 1;
+ *bitP = 0x0;
+ bitmask = 1;
+ }
+
+ if (nulls[i] == 'n')
+ {
+ *infomask |= HEAP_HASNULL;
+ continue;
+ }
+
+ *bitP |= bitmask;
+ }
+
+ switch (att[i]->attlen)
+ {
+ case -1:
+ *infomask |= HEAP_HASVARLENA;
+ if (att[i]->attalign == 'd')
+ {
+ data = (char *) DOUBLEALIGN(data);
+ }
+ else
+ {
+ data = (char *) INTALIGN(data);
+ }
+ data_length = VARSIZE(DatumGetPointer(value[i]));
+ memmove(data, DatumGetPointer(value[i]), data_length);
+ data += data_length;
+ break;
+ case sizeof(char):
+ *data = att[i]->attbyval ?
+ DatumGetChar(value[i]) : *((char *) value[i]);
+ data += sizeof(char);
+ break;
+ case sizeof(int16):
+ data = (char *) SHORTALIGN(data);
+ *(short *) data = (att[i]->attbyval ?
+ DatumGetInt16(value[i]) :
+ *((short *) value[i]));
+ data += sizeof(short);
+ break;
+ case sizeof(int32):
+ data = (char *) INTALIGN(data);
+ *(int32 *) data = (att[i]->attbyval ?
+ DatumGetInt32(value[i]) :
+ *((int32 *) value[i]));
+ data += sizeof(int32);
+ break;
+ default:
+ if (att[i]->attlen < sizeof(int32))
+ elog(WARN, "DataFill: attribute %d has len %d",
+ i, att[i]->attlen);
+ if (att[i]->attalign == 'd')
+ {
+ data = (char *) DOUBLEALIGN(data);
+ memmove(data, DatumGetPointer(value[i]),
+ att[i]->attlen);
+ data += att[i]->attlen;
+ }
+ else
+ {
+ data = (char *) LONGALIGN(data);
+ memmove(data, DatumGetPointer(value[i]),
+ att[i]->attlen);
+ data += att[i]->attlen;
+ }
+ break;
+ }
}
- }
}
/* ----------------------------------------------------------------
- * heap tuple interface
+ * heap tuple interface
* ----------------------------------------------------------------
*/
/* ----------------
- * heap_attisnull - returns 1 iff tuple attribute is not present
+ * heap_attisnull - returns 1 iff tuple attribute is not present
* ----------------
*/
int
heap_attisnull(HeapTuple tup, int attnum)
{
- if (attnum > (int)tup->t_natts)
- return (1);
-
- if (HeapTupleNoNulls(tup)) return(0);
-
- if (attnum > 0) {
- return(att_isnull(attnum - 1, tup->t_bits));
- } else
- switch (attnum) {
- case SelfItemPointerAttributeNumber:
- case ObjectIdAttributeNumber:
- case MinTransactionIdAttributeNumber:
- case MinCommandIdAttributeNumber:
- case MaxTransactionIdAttributeNumber:
- case MaxCommandIdAttributeNumber:
- case ChainItemPointerAttributeNumber:
- case AnchorItemPointerAttributeNumber:
- case MinAbsoluteTimeAttributeNumber:
- case MaxAbsoluteTimeAttributeNumber:
- case VersionTypeAttributeNumber:
- break;
-
- case 0:
- elog(WARN, "heap_attisnull: zero attnum disallowed");
-
- default:
- elog(WARN, "heap_attisnull: undefined negative attnum");
+ if (attnum > (int) tup->t_natts)
+ return (1);
+
+ if (HeapTupleNoNulls(tup))
+ return (0);
+
+ if (attnum > 0)
+ {
+ return (att_isnull(attnum - 1, tup->t_bits));
}
-
- return (0);
+ else
+ switch (attnum)
+ {
+ case SelfItemPointerAttributeNumber:
+ case ObjectIdAttributeNumber:
+ case MinTransactionIdAttributeNumber:
+ case MinCommandIdAttributeNumber:
+ case MaxTransactionIdAttributeNumber:
+ case MaxCommandIdAttributeNumber:
+ case ChainItemPointerAttributeNumber:
+ case AnchorItemPointerAttributeNumber:
+ case MinAbsoluteTimeAttributeNumber:
+ case MaxAbsoluteTimeAttributeNumber:
+ case VersionTypeAttributeNumber:
+ break;
+
+ case 0:
+ elog(WARN, "heap_attisnull: zero attnum disallowed");
+
+ default:
+ elog(WARN, "heap_attisnull: undefined negative attnum");
+ }
+
+ return (0);
}
/* ----------------------------------------------------------------
- * system attribute heap tuple support
+ * system attribute heap tuple support
* ----------------------------------------------------------------
*/
/* ----------------
- * heap_sysattrlen
+ * heap_sysattrlen
*
- * This routine returns the length of a system attribute.
+ * This routine returns the length of a system attribute.
* ----------------
*/
int
heap_sysattrlen(AttrNumber attno)
{
- HeapTupleData *f = NULL;
-
- switch (attno) {
- case SelfItemPointerAttributeNumber: return sizeof f->t_ctid;
- case ObjectIdAttributeNumber: return sizeof f->t_oid;
- case MinTransactionIdAttributeNumber: return sizeof f->t_xmin;
- case MinCommandIdAttributeNumber: return sizeof f->t_cmin;
- case MaxTransactionIdAttributeNumber: return sizeof f->t_xmax;
- case MaxCommandIdAttributeNumber: return sizeof f->t_cmax;
- case ChainItemPointerAttributeNumber: return sizeof f->t_chain;
- case MinAbsoluteTimeAttributeNumber: return sizeof f->t_tmin;
- case MaxAbsoluteTimeAttributeNumber: return sizeof f->t_tmax;
- case VersionTypeAttributeNumber: return sizeof f->t_vtype;
-
- case AnchorItemPointerAttributeNumber:
- elog(WARN, "heap_sysattrlen: field t_anchor does not exist!");
- return 0;
-
- default:
- elog(WARN, "sysattrlen: System attribute number %d unknown.", attno);
- return 0;
- }
+ HeapTupleData *f = NULL;
+
+ switch (attno)
+ {
+ case SelfItemPointerAttributeNumber:
+ return sizeof f->t_ctid;
+ case ObjectIdAttributeNumber:
+ return sizeof f->t_oid;
+ case MinTransactionIdAttributeNumber:
+ return sizeof f->t_xmin;
+ case MinCommandIdAttributeNumber:
+ return sizeof f->t_cmin;
+ case MaxTransactionIdAttributeNumber:
+ return sizeof f->t_xmax;
+ case MaxCommandIdAttributeNumber:
+ return sizeof f->t_cmax;
+ case ChainItemPointerAttributeNumber:
+ return sizeof f->t_chain;
+ case MinAbsoluteTimeAttributeNumber:
+ return sizeof f->t_tmin;
+ case MaxAbsoluteTimeAttributeNumber:
+ return sizeof f->t_tmax;
+ case VersionTypeAttributeNumber:
+ return sizeof f->t_vtype;
+
+ case AnchorItemPointerAttributeNumber:
+ elog(WARN, "heap_sysattrlen: field t_anchor does not exist!");
+ return 0;
+
+ default:
+ elog(WARN, "sysattrlen: System attribute number %d unknown.", attno);
+ return 0;
+ }
}
/* ----------------
- * heap_sysattrbyval
+ * heap_sysattrbyval
*
- * This routine returns the "by-value" property of a system attribute.
+ * This routine returns the "by-value" property of a system attribute.
* ----------------
*/
bool
heap_sysattrbyval(AttrNumber attno)
{
- bool byval;
-
- switch (attno) {
- case SelfItemPointerAttributeNumber:
- byval = false;
- break;
- case ObjectIdAttributeNumber:
- byval = true;
- break;
- case MinTransactionIdAttributeNumber:
- byval = true;
- break;
- case MinCommandIdAttributeNumber:
- byval = true;
- break;
- case MaxTransactionIdAttributeNumber:
- byval = true;
- break;
- case MaxCommandIdAttributeNumber:
- byval = true;
- break;
- case ChainItemPointerAttributeNumber:
- byval = false;
- break;
- case AnchorItemPointerAttributeNumber:
- byval = false;
- break;
- case MinAbsoluteTimeAttributeNumber:
- byval = true;
- break;
- case MaxAbsoluteTimeAttributeNumber:
- byval = true;
- break;
- case VersionTypeAttributeNumber:
- byval = true;
- break;
- default:
- byval = true;
- elog(WARN, "sysattrbyval: System attribute number %d unknown.",
- attno);
- break;
- }
-
- return byval;
+ bool byval;
+
+ switch (attno)
+ {
+ case SelfItemPointerAttributeNumber:
+ byval = false;
+ break;
+ case ObjectIdAttributeNumber:
+ byval = true;
+ break;
+ case MinTransactionIdAttributeNumber:
+ byval = true;
+ break;
+ case MinCommandIdAttributeNumber:
+ byval = true;
+ break;
+ case MaxTransactionIdAttributeNumber:
+ byval = true;
+ break;
+ case MaxCommandIdAttributeNumber:
+ byval = true;
+ break;
+ case ChainItemPointerAttributeNumber:
+ byval = false;
+ break;
+ case AnchorItemPointerAttributeNumber:
+ byval = false;
+ break;
+ case MinAbsoluteTimeAttributeNumber:
+ byval = true;
+ break;
+ case MaxAbsoluteTimeAttributeNumber:
+ byval = true;
+ break;
+ case VersionTypeAttributeNumber:
+ byval = true;
+ break;
+ default:
+ byval = true;
+ elog(WARN, "sysattrbyval: System attribute number %d unknown.",
+ attno);
+ break;
+ }
+
+ return byval;
}
/* ----------------
- * heap_getsysattr
+ * heap_getsysattr
* ----------------
*/
-char *
+char *
heap_getsysattr(HeapTuple tup, Buffer b, int attnum)
{
- switch (attnum) {
- case SelfItemPointerAttributeNumber:
- return ((char *)&tup->t_ctid);
- case ObjectIdAttributeNumber:
- return ((char *) (long) tup->t_oid);
- case MinTransactionIdAttributeNumber:
- return ((char *) (long) tup->t_xmin);
- case MinCommandIdAttributeNumber:
- return ((char *) (long) tup->t_cmin);
- case MaxTransactionIdAttributeNumber:
- return ((char *) (long) tup->t_xmax);
- case MaxCommandIdAttributeNumber:
- return ((char *) (long) tup->t_cmax);
- case ChainItemPointerAttributeNumber:
- return ((char *) &tup->t_chain);
- case AnchorItemPointerAttributeNumber:
- elog(WARN, "heap_getsysattr: t_anchor does not exist!");
- break;
-
- /*
- * For tmin and tmax, we need to do some extra work. These don't
- * get filled in until the vacuum cleaner runs (or we manage to flush
- * a page after setting the value correctly below). If the vacuum
- * cleaner hasn't run yet, then the times stored in the tuple are
- * wrong, and we need to look up the commit time of the transaction.
- * We cache this value in the tuple to avoid doing the work more than
- * once.
- */
-
- case MinAbsoluteTimeAttributeNumber:
- if (!AbsoluteTimeIsBackwardCompatiblyValid(tup->t_tmin) &&
- TransactionIdDidCommit(tup->t_xmin))
- tup->t_tmin = TransactionIdGetCommitTime(tup->t_xmin);
- return ((char *) (long) tup->t_tmin);
- case MaxAbsoluteTimeAttributeNumber:
- if (!AbsoluteTimeIsBackwardCompatiblyReal(tup->t_tmax)) {
- if (TransactionIdDidCommit(tup->t_xmax))
- tup->t_tmax = TransactionIdGetCommitTime(tup->t_xmax);
- else
- tup->t_tmax = CURRENT_ABSTIME;
+ switch (attnum)
+ {
+ case SelfItemPointerAttributeNumber:
+ return ((char *) &tup->t_ctid);
+ case ObjectIdAttributeNumber:
+ return ((char *) (long) tup->t_oid);
+ case MinTransactionIdAttributeNumber:
+ return ((char *) (long) tup->t_xmin);
+ case MinCommandIdAttributeNumber:
+ return ((char *) (long) tup->t_cmin);
+ case MaxTransactionIdAttributeNumber:
+ return ((char *) (long) tup->t_xmax);
+ case MaxCommandIdAttributeNumber:
+ return ((char *) (long) tup->t_cmax);
+ case ChainItemPointerAttributeNumber:
+ return ((char *) &tup->t_chain);
+ case AnchorItemPointerAttributeNumber:
+ elog(WARN, "heap_getsysattr: t_anchor does not exist!");
+ break;
+
+ /*
+ * For tmin and tmax, we need to do some extra work. These don't
+ * get filled in until the vacuum cleaner runs (or we manage to
+ * flush a page after setting the value correctly below). If the
+ * vacuum cleaner hasn't run yet, then the times stored in the
+ * tuple are wrong, and we need to look up the commit time of the
+ * transaction. We cache this value in the tuple to avoid doing
+ * the work more than once.
+ */
+
+ case MinAbsoluteTimeAttributeNumber:
+ if (!AbsoluteTimeIsBackwardCompatiblyValid(tup->t_tmin) &&
+ TransactionIdDidCommit(tup->t_xmin))
+ tup->t_tmin = TransactionIdGetCommitTime(tup->t_xmin);
+ return ((char *) (long) tup->t_tmin);
+ case MaxAbsoluteTimeAttributeNumber:
+ if (!AbsoluteTimeIsBackwardCompatiblyReal(tup->t_tmax))
+ {
+ if (TransactionIdDidCommit(tup->t_xmax))
+ tup->t_tmax = TransactionIdGetCommitTime(tup->t_xmax);
+ else
+ tup->t_tmax = CURRENT_ABSTIME;
+ }
+ return ((char *) (long) tup->t_tmax);
+ case VersionTypeAttributeNumber:
+ return ((char *) (long) tup->t_vtype);
+ default:
+ elog(WARN, "heap_getsysattr: undefined attnum %d", attnum);
}
- return ((char *) (long) tup->t_tmax);
- case VersionTypeAttributeNumber:
- return ((char *) (long) tup->t_vtype);
- default:
- elog(WARN, "heap_getsysattr: undefined attnum %d", attnum);
- }
- return(NULL);
+ return (NULL);
}
/* ----------------
- * fastgetattr
+ * fastgetattr
*
- * This is a newer version of fastgetattr which attempts to be
- * faster by caching attribute offsets in the attribute descriptor.
+ * This is a newer version of fastgetattr which attempts to be
+ * faster by caching attribute offsets in the attribute descriptor.
*
- * an alternate way to speed things up would be to cache offsets
- * with the tuple, but that seems more difficult unless you take
- * the storage hit of actually putting those offsets into the
- * tuple you send to disk. Yuck.
+ * an alternate way to speed things up would be to cache offsets
+ * with the tuple, but that seems more difficult unless you take
+ * the storage hit of actually putting those offsets into the
+ * tuple you send to disk. Yuck.
*
- * This scheme will be slightly slower than that, but should
- * preform well for queries which hit large #'s of tuples. After
- * you cache the offsets once, examining all the other tuples using
- * the same attribute descriptor will go much quicker. -cim 5/4/91
+ * This scheme will be slightly slower than that, but should
+ * preform well for queries which hit large #'s of tuples. After
+ * you cache the offsets once, examining all the other tuples using
+ * the same attribute descriptor will go much quicker. -cim 5/4/91
* ----------------
*/
-char *
+char *
fastgetattr(HeapTuple tup,
- int attnum,
- TupleDesc tupleDesc,
- bool *isnull)
+ int attnum,
+ TupleDesc tupleDesc,
+ bool * isnull)
{
- char *tp; /* ptr to att in tuple */
- bits8 *bp = NULL; /* ptr to att in tuple */
- int slow; /* do we have to walk nulls? */
- AttributeTupleForm *att = tupleDesc->attrs;
-
- /* ----------------
- * sanity checks
- * ----------------
- */
-
- Assert(attnum > 0);
-
- /* ----------------
- * Three cases:
- *
- * 1: No nulls and no variable length attributes.
- * 2: Has a null or a varlena AFTER att.
- * 3: Has nulls or varlenas BEFORE att.
- * ----------------
- */
-
- if (isnull)
- *isnull = false;
-
- if (HeapTupleNoNulls(tup)) {
- attnum--;
- if (att[attnum]->attcacheoff > 0) {
- return (char *)
- fetchatt( &(att[attnum]),
- (char *)tup + tup->t_hoff + att[attnum]->attcacheoff);
- } else if (attnum == 0) {
- /*
- * first attribute is always at position zero
- */
- return((char *) fetchatt(&(att[0]), (char *) tup + tup->t_hoff));
- }
-
- tp = (char *) tup + tup->t_hoff;
-
- slow = 0;
- } else {
- /*
- * there's a null somewhere in the tuple
- */
+ char *tp; /* ptr to att in tuple */
+ bits8 *bp = NULL; /* ptr to att in tuple */
+ int slow; /* do we have to walk nulls? */
+ AttributeTupleForm *att = tupleDesc->attrs;
- bp = tup->t_bits;
- tp = (char *) tup + tup->t_hoff;
- slow = 0;
- attnum--;
-
/* ----------------
- * check to see if desired att is null
+ * sanity checks
* ----------------
*/
-
- if (att_isnull(attnum, bp)) {
- if (isnull)
- *isnull = true;
- return NULL;
- }
+
+ Assert(attnum > 0);
/* ----------------
- * Now check to see if any preceeding bits are null...
+ * Three cases:
+ *
+ * 1: No nulls and no variable length attributes.
+ * 2: Has a null or a varlena AFTER att.
+ * 3: Has nulls or varlenas BEFORE att.
* ----------------
*/
-
+
+ if (isnull)
+ *isnull = false;
+
+ if (HeapTupleNoNulls(tup))
{
- register int i = 0; /* current offset in bp */
-
- for (i = 0; i < attnum && !slow; i++) {
- if (att_isnull(i, bp)) slow = 1;
- }
+ attnum--;
+ if (att[attnum]->attcacheoff > 0)
+ {
+ return (char *)
+ fetchatt(&(att[attnum]),
+ (char *) tup + tup->t_hoff + att[attnum]->attcacheoff);
+ }
+ else if (attnum == 0)
+ {
+
+ /*
+ * first attribute is always at position zero
+ */
+ return ((char *) fetchatt(&(att[0]), (char *) tup + tup->t_hoff));
+ }
+
+ tp = (char *) tup + tup->t_hoff;
+
+ slow = 0;
}
- }
-
- /*
- * now check for any non-fixed length attrs before our attribute
- */
- if (!slow) {
- if (att[attnum]->attcacheoff > 0) {
- return (char *)
- fetchatt(&(att[attnum]),
- tp + att[attnum]->attcacheoff);
- } else if (attnum == 0) {
- return (char *)
- fetchatt(&(att[0]), (char *) tup + tup->t_hoff);
- } else if (!HeapTupleAllFixed(tup)) {
- register int j = 0;
-
- for (j = 0; j < attnum && !slow; j++)
- if (att[j]->attlen < 1) slow = 1;
+ else
+ {
+
+ /*
+ * there's a null somewhere in the tuple
+ */
+
+ bp = tup->t_bits;
+ tp = (char *) tup + tup->t_hoff;
+ slow = 0;
+ attnum--;
+
+ /* ----------------
+ * check to see if desired att is null
+ * ----------------
+ */
+
+ if (att_isnull(attnum, bp))
+ {
+ if (isnull)
+ *isnull = true;
+ return NULL;
+ }
+
+ /* ----------------
+ * Now check to see if any preceeding bits are null...
+ * ----------------
+ */
+
+ {
+ register int i = 0; /* current offset in bp */
+
+ for (i = 0; i < attnum && !slow; i++)
+ {
+ if (att_isnull(i, bp))
+ slow = 1;
+ }
+ }
}
- }
-
- /*
- * if slow is zero, and we got here, we know that we have a tuple with
- * no nulls. We also have to initialize the remainder of
- * the attribute cached offset values.
- */
- if (!slow) {
- register int j = 1;
- register long off;
-
+
/*
- * need to set cache for some atts
+ * now check for any non-fixed length attrs before our attribute
*/
-
- att[0]->attcacheoff = 0;
-
- while (att[j]->attcacheoff > 0) j++;
-
- off = att[j-1]->attcacheoff + att[j-1]->attlen;
-
- for (; j < attnum + 1; j++) {
- switch(att[j]->attlen) {
- case -1:
- off = (att[j]->attalign=='d') ?
- DOUBLEALIGN(off) : INTALIGN(off);
- break;
- case sizeof(char):
- break;
- case sizeof(short):
- off = SHORTALIGN(off);
- break;
- case sizeof(int32):
- off = INTALIGN(off);
- break;
- default:
- if (att[j]->attlen < sizeof(int32)) {
- elog(WARN,
- "fastgetattr: attribute %d has len %d",
- j, att[j]->attlen);
+ if (!slow)
+ {
+ if (att[attnum]->attcacheoff > 0)
+ {
+ return (char *)
+ fetchatt(&(att[attnum]),
+ tp + att[attnum]->attcacheoff);
+ }
+ else if (attnum == 0)
+ {
+ return (char *)
+ fetchatt(&(att[0]), (char *) tup + tup->t_hoff);
+ }
+ else if (!HeapTupleAllFixed(tup))
+ {
+ register int j = 0;
+
+ for (j = 0; j < attnum && !slow; j++)
+ if (att[j]->attlen < 1)
+ slow = 1;
}
- if (att[j]->attalign == 'd')
- off = DOUBLEALIGN(off);
- else
- off = LONGALIGN(off);
- break;
- }
-
- att[j]->attcacheoff = off;
- off += att[j]->attlen;
}
-
- return
- (char *)fetchatt(&(att[attnum]), tp + att[attnum]->attcacheoff);
- } else {
- register bool usecache = true;
- register int off = 0;
- register int i;
-
+
/*
- * Now we know that we have to walk the tuple CAREFULLY.
- *
- * Note - This loop is a little tricky. On iteration i we
- * first set the offset for attribute i and figure out how much
- * the offset should be incremented. Finally, we need to align the
- * offset based on the size of attribute i+1 (for which the offset
- * has been computed). -mer 12 Dec 1991
+ * if slow is zero, and we got here, we know that we have a tuple with
+ * no nulls. We also have to initialize the remainder of the
+ * attribute cached offset values.
*/
-
- for (i = 0; i < attnum; i++) {
- if (!HeapTupleNoNulls(tup)) {
- if (att_isnull(i, bp)) {
- usecache = false;
- continue;
- }
- }
- switch (att[i]->attlen) {
- case -1:
- off = (att[i]->attalign=='d') ?
- DOUBLEALIGN(off) : INTALIGN(off);
- break;
- case sizeof(char):
- break;
- case sizeof(short):
- off = SHORTALIGN(off);
- break;
- case sizeof(int32):
- off = INTALIGN(off);
- break;
- default:
- if (att[i]->attlen < sizeof(int32))
- elog(WARN,
- "fastgetattr2: attribute %d has len %d",
- i, att[i]->attlen);
- if (att[i]->attalign == 'd')
- off = DOUBLEALIGN(off);
- else
- off = LONGALIGN(off);
- break;
- }
- if (usecache && att[i]->attcacheoff > 0) {
- off = att[i]->attcacheoff;
- if (att[i]->attlen == -1) {
- usecache = false;
+ if (!slow)
+ {
+ register int j = 1;
+ register long off;
+
+ /*
+ * need to set cache for some atts
+ */
+
+ att[0]->attcacheoff = 0;
+
+ while (att[j]->attcacheoff > 0)
+ j++;
+
+ off = att[j - 1]->attcacheoff + att[j - 1]->attlen;
+
+ for (; j < attnum + 1; j++)
+ {
+ switch (att[j]->attlen)
+ {
+ case -1:
+ off = (att[j]->attalign == 'd') ?
+ DOUBLEALIGN(off) : INTALIGN(off);
+ break;
+ case sizeof(char):
+ break;
+ case sizeof(short):
+ off = SHORTALIGN(off);
+ break;
+ case sizeof(int32):
+ off = INTALIGN(off);
+ break;
+ default:
+ if (att[j]->attlen < sizeof(int32))
+ {
+ elog(WARN,
+ "fastgetattr: attribute %d has len %d",
+ j, att[j]->attlen);
+ }
+ if (att[j]->attalign == 'd')
+ off = DOUBLEALIGN(off);
+ else
+ off = LONGALIGN(off);
+ break;
+ }
+
+ att[j]->attcacheoff = off;
+ off += att[j]->attlen;
}
- } else {
- if (usecache) att[i]->attcacheoff = off;
- }
-
- switch(att[i]->attlen) {
- case sizeof(char):
- off++;
- break;
- case sizeof(int16):
- off += sizeof(int16);
- break;
- case sizeof(int32):
- off += sizeof(int32);
- break;
- case -1:
- usecache = false;
- off += VARSIZE(tp + off);
- break;
- default:
- off += att[i]->attlen;
- break;
- }
+
+ return
+ (char *) fetchatt(&(att[attnum]), tp + att[attnum]->attcacheoff);
}
- switch (att[attnum]->attlen) {
- case -1:
- off = (att[attnum]->attalign=='d')?
- DOUBLEALIGN(off) : INTALIGN(off);
- break;
- case sizeof(char):
- break;
- case sizeof(short):
- off = SHORTALIGN(off);
- break;
- case sizeof(int32):
- off = INTALIGN(off);
- break;
- default:
- if (att[attnum]->attlen < sizeof(int32))
- elog(WARN, "fastgetattr3: attribute %d has len %d",
- attnum, att[attnum]->attlen);
- if (att[attnum]->attalign == 'd')
- off = DOUBLEALIGN(off);
- else
- off = LONGALIGN(off);
- break;
+ else
+ {
+ register bool usecache = true;
+ register int off = 0;
+ register int i;
+
+ /*
+ * Now we know that we have to walk the tuple CAREFULLY.
+ *
+ * Note - This loop is a little tricky. On iteration i we first set
+ * the offset for attribute i and figure out how much the offset
+ * should be incremented. Finally, we need to align the offset
+ * based on the size of attribute i+1 (for which the offset has
+ * been computed). -mer 12 Dec 1991
+ */
+
+ for (i = 0; i < attnum; i++)
+ {
+ if (!HeapTupleNoNulls(tup))
+ {
+ if (att_isnull(i, bp))
+ {
+ usecache = false;
+ continue;
+ }
+ }
+ switch (att[i]->attlen)
+ {
+ case -1:
+ off = (att[i]->attalign == 'd') ?
+ DOUBLEALIGN(off) : INTALIGN(off);
+ break;
+ case sizeof(char):
+ break;
+ case sizeof(short):
+ off = SHORTALIGN(off);
+ break;
+ case sizeof(int32):
+ off = INTALIGN(off);
+ break;
+ default:
+ if (att[i]->attlen < sizeof(int32))
+ elog(WARN,
+ "fastgetattr2: attribute %d has len %d",
+ i, att[i]->attlen);
+ if (att[i]->attalign == 'd')
+ off = DOUBLEALIGN(off);
+ else
+ off = LONGALIGN(off);
+ break;
+ }
+ if (usecache && att[i]->attcacheoff > 0)
+ {
+ off = att[i]->attcacheoff;
+ if (att[i]->attlen == -1)
+ {
+ usecache = false;
+ }
+ }
+ else
+ {
+ if (usecache)
+ att[i]->attcacheoff = off;
+ }
+
+ switch (att[i]->attlen)
+ {
+ case sizeof(char):
+ off++;
+ break;
+ case sizeof(int16):
+ off += sizeof(int16);
+ break;
+ case sizeof(int32):
+ off += sizeof(int32);
+ break;
+ case -1:
+ usecache = false;
+ off += VARSIZE(tp + off);
+ break;
+ default:
+ off += att[i]->attlen;
+ break;
+ }
+ }
+ switch (att[attnum]->attlen)
+ {
+ case -1:
+ off = (att[attnum]->attalign == 'd') ?
+ DOUBLEALIGN(off) : INTALIGN(off);
+ break;
+ case sizeof(char):
+ break;
+ case sizeof(short):
+ off = SHORTALIGN(off);
+ break;
+ case sizeof(int32):
+ off = INTALIGN(off);
+ break;
+ default:
+ if (att[attnum]->attlen < sizeof(int32))
+ elog(WARN, "fastgetattr3: attribute %d has len %d",
+ attnum, att[attnum]->attlen);
+ if (att[attnum]->attalign == 'd')
+ off = DOUBLEALIGN(off);
+ else
+ off = LONGALIGN(off);
+ break;
+ }
+ return ((char *) fetchatt(&(att[attnum]), tp + off));
}
- return((char *) fetchatt(&(att[attnum]), tp + off));
- }
}
/* ----------------
- * heap_copytuple
+ * heap_copytuple
*
- * returns a copy of an entire tuple
+ * returns a copy of an entire tuple
* ----------------
*/
HeapTuple
heap_copytuple(HeapTuple tuple)
{
- HeapTuple newTuple;
+ HeapTuple newTuple;
- if (! HeapTupleIsValid(tuple))
- return (NULL);
-
- /* XXX For now, just prevent an undetectable executor related error */
- if (tuple->t_len > MAXTUPLEN) {
- elog(WARN, "palloctup: cannot handle length %d tuples",
- tuple->t_len);
- }
-
- newTuple = (HeapTuple) palloc(tuple->t_len);
- memmove((char *) newTuple, (char *) tuple, (int) tuple->t_len);
- return(newTuple);
+ if (!HeapTupleIsValid(tuple))
+ return (NULL);
+
+ /* XXX For now, just prevent an undetectable executor related error */
+ if (tuple->t_len > MAXTUPLEN)
+ {
+ elog(WARN, "palloctup: cannot handle length %d tuples",
+ tuple->t_len);
+ }
+
+ newTuple = (HeapTuple) palloc(tuple->t_len);
+ memmove((char *) newTuple, (char *) tuple, (int) tuple->t_len);
+ return (newTuple);
}
#ifdef NOT_USED
/* ----------------
- * heap_deformtuple
+ * heap_deformtuple
*
- * the inverse of heap_formtuple (see below)
+ * the inverse of heap_formtuple (see below)
* ----------------
*/
void
heap_deformtuple(HeapTuple tuple,
- TupleDesc tdesc,
- Datum values[],
- char nulls[])
+ TupleDesc tdesc,
+ Datum values[],
+ char nulls[])
{
- int i;
- int natts;
-
- Assert(HeapTupleIsValid(tuple));
-
- natts = tuple->t_natts;
- for (i = 0; i<natts; i++) {
- bool isnull;
-
- values[i] = (Datum)heap_getattr(tuple,
- InvalidBuffer,
- i+1,
- tdesc,
- &isnull);
- if (isnull)
- nulls[i] = 'n';
- else
- nulls[i] = ' ';
- }
+ int i;
+ int natts;
+
+ Assert(HeapTupleIsValid(tuple));
+
+ natts = tuple->t_natts;
+ for (i = 0; i < natts; i++)
+ {
+ bool isnull;
+
+ values[i] = (Datum) heap_getattr(tuple,
+ InvalidBuffer,
+ i + 1,
+ tdesc,
+ &isnull);
+ if (isnull)
+ nulls[i] = 'n';
+ else
+ nulls[i] = ' ';
+ }
}
+
#endif
/* ----------------
- * heap_formtuple
+ * heap_formtuple
*
- * constructs a tuple from the given value[] and null[] arrays
+ * constructs a tuple from the given value[] and null[] arrays
*
* old comments
- * Handles alignment by aligning 2 byte attributes on short boundries
- * and 3 or 4 byte attributes on long word boundries on a vax; and
- * aligning non-byte attributes on short boundries on a sun. Does
- * not properly align fixed length arrays of 1 or 2 byte types (yet).
+ * Handles alignment by aligning 2 byte attributes on short boundries
+ * and 3 or 4 byte attributes on long word boundries on a vax; and
+ * aligning non-byte attributes on short boundries on a sun. Does
+ * not properly align fixed length arrays of 1 or 2 byte types (yet).
*
- * Null attributes are indicated by a 'n' in the appropriate byte
- * of the null[]. Non-null attributes are indicated by a ' ' (space).
+ * Null attributes are indicated by a 'n' in the appropriate byte
+ * of the null[]. Non-null attributes are indicated by a ' ' (space).
*
- * Fix me. (Figure that must keep context if debug--allow give oid.)
- * Assumes in order.
+ * Fix me. (Figure that must keep context if debug--allow give oid.)
+ * Assumes in order.
* ----------------
*/
HeapTuple
heap_formtuple(TupleDesc tupleDescriptor,
- Datum value[],
- char nulls[])
+ Datum value[],
+ char nulls[])
{
- char *tp; /* tuple pointer */
- HeapTuple tuple; /* return tuple */
- int bitmaplen;
- long len;
- int hoff;
- bool hasnull = false;
- int i;
- int numberOfAttributes = tupleDescriptor->natts;
-
- len = sizeof *tuple - sizeof tuple->t_bits;
-
- for (i = 0; i < numberOfAttributes && !hasnull; i++) {
- if (nulls[i] != ' ') hasnull = true;
- }
-
- if (numberOfAttributes > MaxHeapAttributeNumber)
- elog(WARN, "heap_formtuple: numberOfAttributes of %d > %d",
- numberOfAttributes, MaxHeapAttributeNumber);
-
- if (hasnull) {
- bitmaplen = BITMAPLEN(numberOfAttributes);
- len += bitmaplen;
- }
-
- hoff = len = DOUBLEALIGN(len); /* be conservative here */
-
- len += ComputeDataSize(tupleDescriptor, value, nulls);
-
- tp = (char *) palloc(len);
- tuple = (HeapTuple) tp;
-
- memset(tp, 0, (int)len);
-
- tuple->t_len = len;
- tuple->t_natts = numberOfAttributes;
- tuple->t_hoff = hoff;
- tuple->t_tmin = INVALID_ABSTIME;
- tuple->t_tmax = CURRENT_ABSTIME;
-
- DataFill((char *)tuple + tuple->t_hoff,
- tupleDescriptor,
- value,
- nulls,
- &tuple->t_infomask,
- (hasnull ? tuple->t_bits : NULL));
-
- return (tuple);
+ char *tp; /* tuple pointer */
+ HeapTuple tuple; /* return tuple */
+ int bitmaplen;
+ long len;
+ int hoff;
+ bool hasnull = false;
+ int i;
+ int numberOfAttributes = tupleDescriptor->natts;
+
+ len = sizeof *tuple - sizeof tuple->t_bits;
+
+ for (i = 0; i < numberOfAttributes && !hasnull; i++)
+ {
+ if (nulls[i] != ' ')
+ hasnull = true;
+ }
+
+ if (numberOfAttributes > MaxHeapAttributeNumber)
+ elog(WARN, "heap_formtuple: numberOfAttributes of %d > %d",
+ numberOfAttributes, MaxHeapAttributeNumber);
+
+ if (hasnull)
+ {
+ bitmaplen = BITMAPLEN(numberOfAttributes);
+ len += bitmaplen;
+ }
+
+ hoff = len = DOUBLEALIGN(len); /* be conservative here */
+
+ len += ComputeDataSize(tupleDescriptor, value, nulls);
+
+ tp = (char *) palloc(len);
+ tuple = (HeapTuple) tp;
+
+ memset(tp, 0, (int) len);
+
+ tuple->t_len = len;
+ tuple->t_natts = numberOfAttributes;
+ tuple->t_hoff = hoff;
+ tuple->t_tmin = INVALID_ABSTIME;
+ tuple->t_tmax = CURRENT_ABSTIME;
+
+ DataFill((char *) tuple + tuple->t_hoff,
+ tupleDescriptor,
+ value,
+ nulls,
+ &tuple->t_infomask,
+ (hasnull ? tuple->t_bits : NULL));
+
+ return (tuple);
}
/* ----------------
- * heap_modifytuple
+ * heap_modifytuple
*
- * forms a new tuple from an old tuple and a set of replacement values.
+ * forms a new tuple from an old tuple and a set of replacement values.
* ----------------
*/
HeapTuple
heap_modifytuple(HeapTuple tuple,
- Buffer buffer,
- Relation relation,
- Datum replValue[],
- char replNull[],
- char repl[])
+ Buffer buffer,
+ Relation relation,
+ Datum replValue[],
+ char replNull[],
+ char repl[])
{
- int attoff;
- int numberOfAttributes;
- Datum *value;
- char *nulls;
- bool isNull;
- HeapTuple newTuple;
- int madecopy;
- uint8 infomask;
-
- /* ----------------
- * sanity checks
- * ----------------
- */
- Assert(HeapTupleIsValid(tuple));
- Assert(BufferIsValid(buffer) || RelationIsValid(relation));
- Assert(HeapTupleIsValid(tuple));
- Assert(PointerIsValid(replValue));
- Assert(PointerIsValid(replNull));
- Assert(PointerIsValid(repl));
-
- /* ----------------
- * if we're pointing to a disk page, then first
- * make a copy of our tuple so that all the attributes
- * are available. XXX this is inefficient -cim
- * ----------------
- */
- madecopy = 0;
- if (BufferIsValid(buffer) == true) {
- relation = (Relation) BufferGetRelation(buffer);
- tuple = heap_copytuple(tuple);
- madecopy = 1;
- }
-
- numberOfAttributes = RelationGetRelationTupleForm(relation)->relnatts;
-
- /* ----------------
- * allocate and fill value[] and nulls[] arrays from either
- * the tuple or the repl information, as appropriate.
- * ----------------
- */
- value = (Datum *) palloc(numberOfAttributes * sizeof *value);
- nulls = (char *) palloc(numberOfAttributes * sizeof *nulls);
-
- for (attoff = 0;
- attoff < numberOfAttributes;
- attoff += 1) {
-
- if (repl[attoff] == ' ') {
- char *attr;
-
- attr =
- heap_getattr(tuple,
- InvalidBuffer,
- AttrOffsetGetAttrNumber(attoff),
- RelationGetTupleDescriptor(relation),
- &isNull) ;
- value[attoff] = PointerGetDatum(attr);
- nulls[attoff] = (isNull) ? 'n' : ' ';
-
- } else if (repl[attoff] != 'r') {
- elog(WARN, "heap_modifytuple: repl is \\%3d", repl[attoff]);
-
- } else { /* == 'r' */
- value[attoff] = replValue[attoff];
- nulls[attoff] = replNull[attoff];
+ int attoff;
+ int numberOfAttributes;
+ Datum *value;
+ char *nulls;
+ bool isNull;
+ HeapTuple newTuple;
+ int madecopy;
+ uint8 infomask;
+
+ /* ----------------
+ * sanity checks
+ * ----------------
+ */
+ Assert(HeapTupleIsValid(tuple));
+ Assert(BufferIsValid(buffer) || RelationIsValid(relation));
+ Assert(HeapTupleIsValid(tuple));
+ Assert(PointerIsValid(replValue));
+ Assert(PointerIsValid(replNull));
+ Assert(PointerIsValid(repl));
+
+ /* ----------------
+ * if we're pointing to a disk page, then first
+ * make a copy of our tuple so that all the attributes
+ * are available. XXX this is inefficient -cim
+ * ----------------
+ */
+ madecopy = 0;
+ if (BufferIsValid(buffer) == true)
+ {
+ relation = (Relation) BufferGetRelation(buffer);
+ tuple = heap_copytuple(tuple);
+ madecopy = 1;
+ }
+
+ numberOfAttributes = RelationGetRelationTupleForm(relation)->relnatts;
+
+ /* ----------------
+ * allocate and fill value[] and nulls[] arrays from either
+ * the tuple or the repl information, as appropriate.
+ * ----------------
+ */
+ value = (Datum *) palloc(numberOfAttributes * sizeof *value);
+ nulls = (char *) palloc(numberOfAttributes * sizeof *nulls);
+
+ for (attoff = 0;
+ attoff < numberOfAttributes;
+ attoff += 1)
+ {
+
+ if (repl[attoff] == ' ')
+ {
+ char *attr;
+
+ attr =
+ heap_getattr(tuple,
+ InvalidBuffer,
+ AttrOffsetGetAttrNumber(attoff),
+ RelationGetTupleDescriptor(relation),
+ &isNull);
+ value[attoff] = PointerGetDatum(attr);
+ nulls[attoff] = (isNull) ? 'n' : ' ';
+
+ }
+ else if (repl[attoff] != 'r')
+ {
+ elog(WARN, "heap_modifytuple: repl is \\%3d", repl[attoff]);
+
+ }
+ else
+ { /* == 'r' */
+ value[attoff] = replValue[attoff];
+ nulls[attoff] = replNull[attoff];
+ }
}
- }
-
- /* ----------------
- * create a new tuple from the values[] and nulls[] arrays
- * ----------------
- */
- newTuple = heap_formtuple(RelationGetTupleDescriptor(relation),
- value,
- nulls);
-
- /* ----------------
- * copy the header except for t_len, t_natts, t_hoff, t_bits, t_infomask
- * ----------------
- */
- infomask = newTuple->t_infomask;
- memmove((char *) &newTuple->t_ctid, /*XXX*/
- (char *) &tuple->t_ctid,
- ((char *) &tuple->t_hoff - (char *) &tuple->t_ctid)); /*XXX*/
- newTuple->t_infomask = infomask;
- newTuple->t_natts = numberOfAttributes; /* fix t_natts just in case */
-
- /* ----------------
- * if we made a copy of the tuple, then free it.
- * ----------------
- */
- if (madecopy)
- pfree(tuple);
-
- return
- newTuple;
+
+ /* ----------------
+ * create a new tuple from the values[] and nulls[] arrays
+ * ----------------
+ */
+ newTuple = heap_formtuple(RelationGetTupleDescriptor(relation),
+ value,
+ nulls);
+
+ /* ----------------
+ * copy the header except for t_len, t_natts, t_hoff, t_bits, t_infomask
+ * ----------------
+ */
+ infomask = newTuple->t_infomask;
+ memmove((char *) &newTuple->t_ctid, /* XXX */
+ (char *) &tuple->t_ctid,
+ ((char *) &tuple->t_hoff - (char *) &tuple->t_ctid)); /* XXX */
+ newTuple->t_infomask = infomask;
+ newTuple->t_natts = numberOfAttributes; /* fix t_natts just in
+ * case */
+
+ /* ----------------
+ * if we made a copy of the tuple, then free it.
+ * ----------------
+ */
+ if (madecopy)
+ pfree(tuple);
+
+ return
+ newTuple;
}
/* ----------------------------------------------------------------
- * other misc functions
+ * other misc functions
* ----------------------------------------------------------------
*/
HeapTuple
heap_addheader(uint32 natts, /* max domain index */
- int structlen, /* its length */
- char *structure) /* pointer to the struct */
+ int structlen, /* its length */
+ char *structure) /* pointer to the struct */
{
- register char *tp; /* tuple data pointer */
- HeapTuple tup;
- long len;
- int hoff;
-
- AssertArg(natts > 0);
-
- len = sizeof (HeapTupleData) - sizeof (tup->t_bits);
-
- hoff = len = DOUBLEALIGN(len); /* be conservative */
- len += structlen;
- tp = (char *) palloc(len);
- tup = (HeapTuple) tp;
- memset((char*)tup, 0, len);
-
- tup->t_len = (short) len; /* XXX */
- tp += tup->t_hoff = hoff;
- tup->t_natts = natts;
- tup->t_infomask = 0;
-
- memmove(tp, structure, structlen);
-
- return (tup);
+ register char *tp; /* tuple data pointer */
+ HeapTuple tup;
+ long len;
+ int hoff;
+
+ AssertArg(natts > 0);
+
+ len = sizeof(HeapTupleData) - sizeof(tup->t_bits);
+
+ hoff = len = DOUBLEALIGN(len); /* be conservative */
+ len += structlen;
+ tp = (char *) palloc(len);
+ tup = (HeapTuple) tp;
+ memset((char *) tup, 0, len);
+
+ tup->t_len = (short) len; /* XXX */
+ tp += tup->t_hoff = hoff;
+ tup->t_natts = natts;
+ tup->t_infomask = 0;
+
+ memmove(tp, structure, structlen);
+
+ return (tup);
}
diff --git a/src/backend/access/common/heapvalid.c b/src/backend/access/common/heapvalid.c
index 186ee654b3..0caeb54e17 100644
--- a/src/backend/access/common/heapvalid.c
+++ b/src/backend/access/common/heapvalid.c
@@ -1,13 +1,13 @@
/*-------------------------------------------------------------------------
*
* heapvalid.c--
- * heap tuple qualification validity checking code
+ * heap tuple qualification validity checking code
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/Attic/heapvalid.c,v 1.16 1997/08/29 09:12:20 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/Attic/heapvalid.c,v 1.17 1997/09/07 04:37:36 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -25,128 +25,138 @@
#include <utils/builtins.h>
/* ----------------
- * heap_keytest
+ * heap_keytest
*
- * Test a heap tuple with respect to a scan key.
+ * Test a heap tuple with respect to a scan key.
* ----------------
*/
bool
heap_keytest(HeapTuple t,
- TupleDesc tupdesc,
- int nkeys,
- ScanKey keys)
+ TupleDesc tupdesc,
+ int nkeys,
+ ScanKey keys)
{
- bool isnull;
- Datum atp;
- int test;
-
- for (; nkeys--; keys++) {
- atp = (Datum)heap_getattr(t, InvalidBuffer,
- keys->sk_attno,
- tupdesc,
- &isnull);
-
- if (isnull)
- /* XXX eventually should check if SK_ISNULL */
- return false;
-
- if (keys->sk_flags & SK_ISNULL) {
- return (false);
+ bool isnull;
+ Datum atp;
+ int test;
+
+ for (; nkeys--; keys++)
+ {
+ atp = (Datum) heap_getattr(t, InvalidBuffer,
+ keys->sk_attno,
+ tupdesc,
+ &isnull);
+
+ if (isnull)
+ /* XXX eventually should check if SK_ISNULL */
+ return false;
+
+ if (keys->sk_flags & SK_ISNULL)
+ {
+ return (false);
+ }
+
+ if (keys->sk_func == (func_ptr) oideq) /* optimization */
+ test = (keys->sk_argument == atp);
+ else if (keys->sk_flags & SK_COMMUTE)
+ test = (long) FMGR_PTR2(keys->sk_func, keys->sk_procedure,
+ keys->sk_argument, atp);
+ else
+ test = (long) FMGR_PTR2(keys->sk_func, keys->sk_procedure,
+ atp, keys->sk_argument);
+
+ if (!test == !(keys->sk_flags & SK_NEGATE))
+ return false;
}
- if (keys->sk_func == (func_ptr)oideq) /* optimization */
- test = (keys->sk_argument == atp);
- else if (keys->sk_flags & SK_COMMUTE)
- test = (long) FMGR_PTR2(keys->sk_func, keys->sk_procedure,
- keys->sk_argument, atp);
- else
- test = (long) FMGR_PTR2(keys->sk_func, keys->sk_procedure,
- atp, keys->sk_argument);
-
- if (!test == !(keys->sk_flags & SK_NEGATE))
- return false;
- }
-
- return true;
+ return true;
}
/* ----------------
- * heap_tuple_satisfies
+ * heap_tuple_satisfies
*
- * Returns a valid HeapTuple if it satisfies the timequal and keytest.
- * Returns NULL otherwise. Used to be heap_satisifies (sic) which
- * returned a boolean. It now returns a tuple so that we can avoid doing two
- * PageGetItem's per tuple.
+ * Returns a valid HeapTuple if it satisfies the timequal and keytest.
+ * Returns NULL otherwise. Used to be heap_satisifies (sic) which
+ * returned a boolean. It now returns a tuple so that we can avoid doing two
+ * PageGetItem's per tuple.
*
- * Complete check of validity including LP_CTUP and keytest.
- * This should perhaps be combined with valid somehow in the
- * future. (Also, additional rule tests/time range tests.)
+ * Complete check of validity including LP_CTUP and keytest.
+ * This should perhaps be combined with valid somehow in the
+ * future. (Also, additional rule tests/time range tests.)
*
- * on 8/21/92 mao says: i rearranged the tests here to do keytest before
- * SatisfiesTimeQual. profiling indicated that even for vacuumed relations,
- * time qual checking was more expensive than key testing. time qual is
- * least likely to fail, too. we should really add the time qual test to
- * the restriction and optimize it in the normal way. this has interactions
- * with joey's expensive function work.
+ * on 8/21/92 mao says: i rearranged the tests here to do keytest before
+ * SatisfiesTimeQual. profiling indicated that even for vacuumed relations,
+ * time qual checking was more expensive than key testing. time qual is
+ * least likely to fail, too. we should really add the time qual test to
+ * the restriction and optimize it in the normal way. this has interactions
+ * with joey's expensive function work.
* ----------------
*/
HeapTuple
heap_tuple_satisfies(ItemId itemId,
- Relation relation,
- Buffer buffer,
- PageHeader disk_page,
- TimeQual qual,
- int nKeys,
- ScanKey key)
+ Relation relation,
+ Buffer buffer,
+ PageHeader disk_page,
+ TimeQual qual,
+ int nKeys,
+ ScanKey key)
{
- HeapTuple tuple, result;
- bool res;
- TransactionId old_tmin, old_tmax;
-
- if (! ItemIdIsUsed(itemId))
- return NULL;
-
- tuple = (HeapTuple) PageGetItem((Page) disk_page, itemId);
-
- if (key != NULL)
- res = heap_keytest(tuple, RelationGetTupleDescriptor(relation),
- nKeys, key);
- else
- res = TRUE;
-
- result = (HeapTuple)NULL;
- if (res) {
- if(relation->rd_rel->relkind == RELKIND_UNCATALOGED) {
- result = tuple;
- } else {
- old_tmin = tuple->t_tmin;
- old_tmax = tuple->t_tmax;
- res = HeapTupleSatisfiesTimeQual(tuple,qual);
- if(tuple->t_tmin != old_tmin ||
- tuple->t_tmax != old_tmax) {
- SetBufferCommitInfoNeedsSave(buffer);
- }
- if(res) {
- result = tuple;
- }
+ HeapTuple tuple,
+ result;
+ bool res;
+ TransactionId old_tmin,
+ old_tmax;
+
+ if (!ItemIdIsUsed(itemId))
+ return NULL;
+
+ tuple = (HeapTuple) PageGetItem((Page) disk_page, itemId);
+
+ if (key != NULL)
+ res = heap_keytest(tuple, RelationGetTupleDescriptor(relation),
+ nKeys, key);
+ else
+ res = TRUE;
+
+ result = (HeapTuple) NULL;
+ if (res)
+ {
+ if (relation->rd_rel->relkind == RELKIND_UNCATALOGED)
+ {
+ result = tuple;
+ }
+ else
+ {
+ old_tmin = tuple->t_tmin;
+ old_tmax = tuple->t_tmax;
+ res = HeapTupleSatisfiesTimeQual(tuple, qual);
+ if (tuple->t_tmin != old_tmin ||
+ tuple->t_tmax != old_tmax)
+ {
+ SetBufferCommitInfoNeedsSave(buffer);
+ }
+ if (res)
+ {
+ result = tuple;
+ }
+ }
}
- }
- return result;
+ return result;
}
/*
- * TupleUpdatedByCurXactAndCmd() -- Returns true if this tuple has
- * already been updated once by the current transaction/command
- * pair.
+ * TupleUpdatedByCurXactAndCmd() -- Returns true if this tuple has
+ * already been updated once by the current transaction/command
+ * pair.
*/
bool
TupleUpdatedByCurXactAndCmd(HeapTuple t)
{
- if (TransactionIdEquals(t->t_xmax,
- GetCurrentTransactionId()) &&
- CommandIdGEScanCommandId (t->t_cmax))
- return true;
-
- return false;
+ if (TransactionIdEquals(t->t_xmax,
+ GetCurrentTransactionId()) &&
+ CommandIdGEScanCommandId(t->t_cmax))
+ return true;
+
+ return false;
}
diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c
index a71fc46dc9..c133693801 100644
--- a/src/backend/access/common/indextuple.c
+++ b/src/backend/access/common/indextuple.c
@@ -1,14 +1,14 @@
/*-------------------------------------------------------------------------
*
* indextuple.c--
- * This file contains index tuple accessor and mutator routines,
- * as well as a few various tuple utilities.
+ * This file contains index tuple accessor and mutator routines,
+ * as well as a few various tuple utilities.
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.15 1997/08/19 21:28:50 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.16 1997/09/07 04:37:37 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -21,402 +21,438 @@
#include <access/tupmacs.h>
#ifndef HAVE_MEMMOVE
-# include <regex/utils.h>
+#include <regex/utils.h>
#else
-# include <string.h>
+#include <string.h>
#endif
-static Size IndexInfoFindDataOffset(unsigned short t_info);
-static char *fastgetiattr(IndexTuple tup, int attnum,
- TupleDesc att, bool *isnull);
+static Size IndexInfoFindDataOffset(unsigned short t_info);
+static char *
+fastgetiattr(IndexTuple tup, int attnum,
+ TupleDesc att, bool * isnull);
/* ----------------------------------------------------------------
- * index_ tuple interface routines
+ * index_ tuple interface routines
* ----------------------------------------------------------------
*/
/* ----------------
- * index_formtuple
+ * index_formtuple
* ----------------
*/
IndexTuple
index_formtuple(TupleDesc tupleDescriptor,
- Datum value[],
- char null[])
+ Datum value[],
+ char null[])
{
- register char *tp; /* tuple pointer */
- IndexTuple tuple; /* return tuple */
- Size size, hoff;
- int i;
- unsigned short infomask = 0;
- bool hasnull = false;
- char tupmask = 0;
- int numberOfAttributes = tupleDescriptor->natts;
-
- if (numberOfAttributes > MaxIndexAttributeNumber)
- elog(WARN, "index_formtuple: numberOfAttributes of %d > %d",
- numberOfAttributes, MaxIndexAttributeNumber);
-
-
- for (i = 0; i < numberOfAttributes && !hasnull; i++) {
- if (null[i] != ' ') hasnull = true;
- }
-
- if (hasnull) infomask |= INDEX_NULL_MASK;
-
- hoff = IndexInfoFindDataOffset(infomask);
- size = hoff
- + ComputeDataSize(tupleDescriptor,
- value, null);
- size = DOUBLEALIGN(size); /* be conservative */
-
- tp = (char *) palloc(size);
- tuple = (IndexTuple) tp;
- memset(tp,0,(int)size);
-
- DataFill((char *)tp + hoff,
- tupleDescriptor,
- value,
- null,
- &tupmask,
- (hasnull ? (bits8*)tp + sizeof(*tuple) : NULL));
-
- /*
- * We do this because DataFill wants to initialize a "tupmask" which
- * is used for HeapTuples, but we want an indextuple infomask. The only
- * "relevent" info is the "has variable attributes" field, which is in
- * mask position 0x02. We have already set the null mask above.
- */
-
- if (tupmask & 0x02) infomask |= INDEX_VAR_MASK;
-
- /*
- * Here we make sure that we can actually hold the size. We also want
- * to make sure that size is not aligned oddly. This actually is a
- * rather odd way to make sure the size is not too large overall.
- */
-
- if (size & 0xE000)
- elog(WARN, "index_formtuple: data takes %d bytes: too big", size);
-
-
- infomask |= size;
-
- /* ----------------
- * initialize metadata
- * ----------------
- */
- tuple->t_info = infomask;
- return (tuple);
+ register char *tp; /* tuple pointer */
+ IndexTuple tuple; /* return tuple */
+ Size size,
+ hoff;
+ int i;
+ unsigned short infomask = 0;
+ bool hasnull = false;
+ char tupmask = 0;
+ int numberOfAttributes = tupleDescriptor->natts;
+
+ if (numberOfAttributes > MaxIndexAttributeNumber)
+ elog(WARN, "index_formtuple: numberOfAttributes of %d > %d",
+ numberOfAttributes, MaxIndexAttributeNumber);
+
+
+ for (i = 0; i < numberOfAttributes && !hasnull; i++)
+ {
+ if (null[i] != ' ')
+ hasnull = true;
+ }
+
+ if (hasnull)
+ infomask |= INDEX_NULL_MASK;
+
+ hoff = IndexInfoFindDataOffset(infomask);
+ size = hoff
+ + ComputeDataSize(tupleDescriptor,
+ value, null);
+ size = DOUBLEALIGN(size); /* be conservative */
+
+ tp = (char *) palloc(size);
+ tuple = (IndexTuple) tp;
+ memset(tp, 0, (int) size);
+
+ DataFill((char *) tp + hoff,
+ tupleDescriptor,
+ value,
+ null,
+ &tupmask,
+ (hasnull ? (bits8 *) tp + sizeof(*tuple) : NULL));
+
+ /*
+ * We do this because DataFill wants to initialize a "tupmask" which
+ * is used for HeapTuples, but we want an indextuple infomask. The
+ * only "relevent" info is the "has variable attributes" field, which
+ * is in mask position 0x02. We have already set the null mask above.
+ */
+
+ if (tupmask & 0x02)
+ infomask |= INDEX_VAR_MASK;
+
+ /*
+ * Here we make sure that we can actually hold the size. We also want
+ * to make sure that size is not aligned oddly. This actually is a
+ * rather odd way to make sure the size is not too large overall.
+ */
+
+ if (size & 0xE000)
+ elog(WARN, "index_formtuple: data takes %d bytes: too big", size);
+
+
+ infomask |= size;
+
+ /* ----------------
+ * initialize metadata
+ * ----------------
+ */
+ tuple->t_info = infomask;
+ return (tuple);
}
/* ----------------
- * fastgetiattr
+ * fastgetiattr
*
- * This is a newer version of fastgetiattr which attempts to be
- * faster by caching attribute offsets in the attribute descriptor.
+ * This is a newer version of fastgetiattr which attempts to be
+ * faster by caching attribute offsets in the attribute descriptor.
*
- * an alternate way to speed things up would be to cache offsets
- * with the tuple, but that seems more difficult unless you take
- * the storage hit of actually putting those offsets into the
- * tuple you send to disk. Yuck.
+ * an alternate way to speed things up would be to cache offsets
+ * with the tuple, but that seems more difficult unless you take
+ * the storage hit of actually putting those offsets into the
+ * tuple you send to disk. Yuck.
*
- * This scheme will be slightly slower than that, but should
- * preform well for queries which hit large #'s of tuples. After
- * you cache the offsets once, examining all the other tuples using
- * the same attribute descriptor will go much quicker. -cim 5/4/91
+ * This scheme will be slightly slower than that, but should
+ * preform well for queries which hit large #'s of tuples. After
+ * you cache the offsets once, examining all the other tuples using
+ * the same attribute descriptor will go much quicker. -cim 5/4/91
* ----------------
*/
-static char *
+static char *
fastgetiattr(IndexTuple tup,
- int attnum,
- TupleDesc tupleDesc,
- bool *isnull)
+ int attnum,
+ TupleDesc tupleDesc,
+ bool * isnull)
{
- register char *tp; /* ptr to att in tuple */
- register char *bp = NULL; /* ptr to att in tuple */
- int slow; /* do we have to walk nulls? */
- register int data_off; /* tuple data offset */
- AttributeTupleForm *att = tupleDesc->attrs;
-
- /* ----------------
- * sanity checks
- * ----------------
- */
-
- Assert(PointerIsValid(isnull));
- Assert(attnum > 0);
-
- /* ----------------
- * Three cases:
- *
- * 1: No nulls and no variable length attributes.
- * 2: Has a null or a varlena AFTER att.
- * 3: Has nulls or varlenas BEFORE att.
- * ----------------
- */
-
- *isnull = false;
- data_off = IndexTupleHasMinHeader(tup) ? sizeof *tup :
- IndexInfoFindDataOffset(tup->t_info);
-
- if (IndexTupleNoNulls(tup)) {
-
- /* first attribute is always at position zero */
-
- if (attnum == 1) {
- return(fetchatt(&(att[0]), (char *) tup + data_off));
- }
- attnum--;
-
- if (att[attnum]->attcacheoff > 0) {
- return(fetchatt(&(att[attnum]),
- (char *) tup + data_off +
- att[attnum]->attcacheoff));
- }
-
- tp = (char *) tup + data_off;
-
- slow = 0;
- }else { /* there's a null somewhere in the tuple */
-
- bp = (char *) tup + sizeof(*tup); /* "knows" t_bits are here! */
- slow = 0;
+ register char *tp; /* ptr to att in tuple */
+ register char *bp = NULL; /* ptr to att in tuple */
+ int slow; /* do we have to walk nulls? */
+ register int data_off; /* tuple data offset */
+ AttributeTupleForm *att = tupleDesc->attrs;
+
/* ----------------
- * check to see if desired att is null
+ * sanity checks
* ----------------
*/
-
- attnum--;
- {
- if (att_isnull(attnum, bp)) {
- *isnull = true;
- return NULL;
- }
- }
+
+ Assert(PointerIsValid(isnull));
+ Assert(attnum > 0);
+
/* ----------------
- * Now check to see if any preceeding bits are null...
+ * Three cases:
+ *
+ * 1: No nulls and no variable length attributes.
+ * 2: Has a null or a varlena AFTER att.
+ * 3: Has nulls or varlenas BEFORE att.
* ----------------
*/
+
+ *isnull = false;
+ data_off = IndexTupleHasMinHeader(tup) ? sizeof *tup :
+ IndexInfoFindDataOffset(tup->t_info);
+
+ if (IndexTupleNoNulls(tup))
{
- register int i = 0; /* current offset in bp */
- register int mask; /* bit in byte we're looking at */
- register char n; /* current byte in bp */
- register int byte, finalbit;
-
- byte = attnum >> 3;
- finalbit = attnum & 0x07;
-
- for (; i <= byte; i++) {
- n = bp[i];
- if (i < byte) {
- /* check for nulls in any "earlier" bytes */
- if ((~n) != 0) {
- slow++;
- break;
- }
- } else {
- /* check for nulls "before" final bit of last byte*/
- mask = (finalbit << 1) - 1;
- if ((~n) & mask)
- slow++;
+
+ /* first attribute is always at position zero */
+
+ if (attnum == 1)
+ {
+ return (fetchatt(&(att[0]), (char *) tup + data_off));
+ }
+ attnum--;
+
+ if (att[attnum]->attcacheoff > 0)
+ {
+ return (fetchatt(&(att[attnum]),
+ (char *) tup + data_off +
+ att[attnum]->attcacheoff));
}
- }
+
+ tp = (char *) tup + data_off;
+
+ slow = 0;
}
- tp = (char *) tup + data_off;
- }
-
- /* now check for any non-fixed length attrs before our attribute */
-
- if (!slow) {
- if (att[attnum]->attcacheoff > 0) {
- return(fetchatt(&(att[attnum]),
- tp + att[attnum]->attcacheoff));
- }else if (!IndexTupleAllFixed(tup)) {
- register int j = 0;
-
- for (j = 0; j < attnum && !slow; j++)
- if (att[j]->attlen < 1) slow = 1;
+ else
+ { /* there's a null somewhere in the tuple */
+
+ bp = (char *) tup + sizeof(*tup); /* "knows" t_bits are
+ * here! */
+ slow = 0;
+ /* ----------------
+ * check to see if desired att is null
+ * ----------------
+ */
+
+ attnum--;
+ {
+ if (att_isnull(attnum, bp))
+ {
+ *isnull = true;
+ return NULL;
+ }
+ }
+ /* ----------------
+ * Now check to see if any preceeding bits are null...
+ * ----------------
+ */
+ {
+ register int i = 0; /* current offset in bp */
+ register int mask; /* bit in byte we're looking at */
+ register char n; /* current byte in bp */
+ register int byte,
+ finalbit;
+
+ byte = attnum >> 3;
+ finalbit = attnum & 0x07;
+
+ for (; i <= byte; i++)
+ {
+ n = bp[i];
+ if (i < byte)
+ {
+ /* check for nulls in any "earlier" bytes */
+ if ((~n) != 0)
+ {
+ slow++;
+ break;
+ }
+ }
+ else
+ {
+ /* check for nulls "before" final bit of last byte */
+ mask = (finalbit << 1) - 1;
+ if ((~n) & mask)
+ slow++;
+ }
+ }
+ }
+ tp = (char *) tup + data_off;
}
- }
-
- /*
- * if slow is zero, and we got here, we know that we have a tuple with
- * no nulls. We also know that we have to initialize the remainder of
- * the attribute cached offset values.
- */
-
- if (!slow) {
- register int j = 1;
- register long off;
-
- /*
- * need to set cache for some atts
- */
-
- att[0]->attcacheoff = 0;
-
- while (att[j]->attcacheoff > 0) j++;
-
- off = att[j-1]->attcacheoff +
- att[j-1]->attlen;
-
- for (; j < attnum + 1; j++) {
- /*
- * Fix me when going to a machine with more than a four-byte
- * word!
- */
-
- switch(att[j]->attlen)
+
+ /* now check for any non-fixed length attrs before our attribute */
+
+ if (!slow)
+ {
+ if (att[attnum]->attcacheoff > 0)
{
- case -1:
- off = (att[j]->attalign=='d')?
- DOUBLEALIGN(off):INTALIGN(off);
- break;
- case sizeof(char):
- break;
- case sizeof(short):
- off = SHORTALIGN(off);
- break;
- case sizeof(int32):
- off = INTALIGN(off);
- break;
- default:
- if (att[j]->attlen > sizeof(int32))
- off = (att[j]->attalign=='d')?
- DOUBLEALIGN(off) : LONGALIGN(off);
- else
- elog(WARN, "fastgetiattr: attribute %d has len %d",
- j, att[j]->attlen);
- break;
-
+ return (fetchatt(&(att[attnum]),
+ tp + att[attnum]->attcacheoff));
+ }
+ else if (!IndexTupleAllFixed(tup))
+ {
+ register int j = 0;
+
+ for (j = 0; j < attnum && !slow; j++)
+ if (att[j]->attlen < 1)
+ slow = 1;
}
-
- att[j]->attcacheoff = off;
- off += att[j]->attlen;
}
-
- return(fetchatt( &(att[attnum]),
- tp + att[attnum]->attcacheoff));
- }else {
- register bool usecache = true;
- register int off = 0;
- register int i;
-
+
/*
- * Now we know that we have to walk the tuple CAREFULLY.
+ * if slow is zero, and we got here, we know that we have a tuple with
+ * no nulls. We also know that we have to initialize the remainder of
+ * the attribute cached offset values.
*/
-
- for (i = 0; i < attnum; i++) {
- if (!IndexTupleNoNulls(tup)) {
- if (att_isnull(i, bp)) {
- usecache = false;
- continue;
+
+ if (!slow)
+ {
+ register int j = 1;
+ register long off;
+
+ /*
+ * need to set cache for some atts
+ */
+
+ att[0]->attcacheoff = 0;
+
+ while (att[j]->attcacheoff > 0)
+ j++;
+
+ off = att[j - 1]->attcacheoff +
+ att[j - 1]->attlen;
+
+ for (; j < attnum + 1; j++)
+ {
+
+ /*
+ * Fix me when going to a machine with more than a four-byte
+ * word!
+ */
+
+ switch (att[j]->attlen)
+ {
+ case -1:
+ off = (att[j]->attalign == 'd') ?
+ DOUBLEALIGN(off) : INTALIGN(off);
+ break;
+ case sizeof(char):
+ break;
+ case sizeof(short):
+ off = SHORTALIGN(off);
+ break;
+ case sizeof(int32):
+ off = INTALIGN(off);
+ break;
+ default:
+ if (att[j]->attlen > sizeof(int32))
+ off = (att[j]->attalign == 'd') ?
+ DOUBLEALIGN(off) : LONGALIGN(off);
+ else
+ elog(WARN, "fastgetiattr: attribute %d has len %d",
+ j, att[j]->attlen);
+ break;
+
+ }
+
+ att[j]->attcacheoff = off;
+ off += att[j]->attlen;
}
- }
-
- if (usecache && att[i]->attcacheoff > 0) {
- off = att[i]->attcacheoff;
- if (att[i]->attlen == -1)
- usecache = false;
- else
- continue;
- }
-
- if (usecache) att[i]->attcacheoff = off;
- switch(att[i]->attlen)
+
+ return (fetchatt(&(att[attnum]),
+ tp + att[attnum]->attcacheoff));
+ }
+ else
+ {
+ register bool usecache = true;
+ register int off = 0;
+ register int i;
+
+ /*
+ * Now we know that we have to walk the tuple CAREFULLY.
+ */
+
+ for (i = 0; i < attnum; i++)
{
+ if (!IndexTupleNoNulls(tup))
+ {
+ if (att_isnull(i, bp))
+ {
+ usecache = false;
+ continue;
+ }
+ }
+
+ if (usecache && att[i]->attcacheoff > 0)
+ {
+ off = att[i]->attcacheoff;
+ if (att[i]->attlen == -1)
+ usecache = false;
+ else
+ continue;
+ }
+
+ if (usecache)
+ att[i]->attcacheoff = off;
+ switch (att[i]->attlen)
+ {
+ case sizeof(char):
+ off++;
+ break;
+ case sizeof(short):
+ off = SHORTALIGN(off) +sizeof(short);
+ break;
+ case sizeof(int32):
+ off = INTALIGN(off) + sizeof(int32);
+ break;
+ case -1:
+ usecache = false;
+ off = (att[i]->attalign == 'd') ?
+ DOUBLEALIGN(off) : INTALIGN(off);
+ off += VARSIZE(tp + off);
+ break;
+ default:
+ if (att[i]->attlen > sizeof(int32))
+ off = (att[i]->attalign == 'd') ?
+ DOUBLEALIGN(off) + att[i]->attlen :
+ LONGALIGN(off) + att[i]->attlen;
+ else
+ elog(WARN, "fastgetiattr2: attribute %d has len %d",
+ i, att[i]->attlen);
+
+ break;
+ }
+ }
+
+ /*
+ * I don't know why this code was missed here! I've got it from
+ * heaptuple.c:fastgetattr(). - vadim 06/12/97
+ */
+ switch (att[attnum]->attlen)
+ {
+ case -1:
+ off = (att[attnum]->attalign == 'd') ?
+ DOUBLEALIGN(off) : INTALIGN(off);
+ break;
case sizeof(char):
- off++;
- break;
+ break;
case sizeof(short):
- off = SHORTALIGN(off) + sizeof(short);
- break;
+ off = SHORTALIGN(off);
+ break;
case sizeof(int32):
- off = INTALIGN(off) + sizeof(int32);
- break;
- case -1:
- usecache = false;
- off = (att[i]->attalign=='d')?
- DOUBLEALIGN(off):INTALIGN(off);
- off += VARSIZE(tp + off);
- break;
+ off = INTALIGN(off);
+ break;
default:
- if (att[i]->attlen > sizeof(int32))
- off = (att[i]->attalign=='d') ?
- DOUBLEALIGN(off) + att[i]->attlen :
- LONGALIGN(off) + att[i]->attlen;
- else
- elog(WARN, "fastgetiattr2: attribute %d has len %d",
- i, att[i]->attlen);
-
- break;
+ if (att[attnum]->attlen < sizeof(int32))
+ elog(WARN, "fastgetattr3: attribute %d has len %d",
+ attnum, att[attnum]->attlen);
+ if (att[attnum]->attalign == 'd')
+ off = DOUBLEALIGN(off);
+ else
+ off = LONGALIGN(off);
+ break;
}
+
+ return (fetchatt(&att[attnum], tp + off));
}
- /*
- * I don't know why this code was missed here!
- * I've got it from heaptuple.c:fastgetattr().
- * - vadim 06/12/97
- */
- switch (att[attnum]->attlen) {
- case -1:
- off = (att[attnum]->attalign=='d')?
- DOUBLEALIGN(off) : INTALIGN(off);
- break;
- case sizeof(char):
- break;
- case sizeof(short):
- off = SHORTALIGN(off);
- break;
- case sizeof(int32):
- off = INTALIGN(off);
- break;
- default:
- if (att[attnum]->attlen < sizeof(int32))
- elog(WARN, "fastgetattr3: attribute %d has len %d",
- attnum, att[attnum]->attlen);
- if (att[attnum]->attalign == 'd')
- off = DOUBLEALIGN(off);
- else
- off = LONGALIGN(off);
- break;
- }
-
- return(fetchatt(&att[attnum], tp + off));
- }
}
/* ----------------
- * index_getattr
+ * index_getattr
* ----------------
*/
Datum
index_getattr(IndexTuple tuple,
- AttrNumber attNum,
- TupleDesc tupDesc,
- bool *isNullOutP)
+ AttrNumber attNum,
+ TupleDesc tupDesc,
+ bool * isNullOutP)
{
- Assert (attNum > 0);
+ Assert(attNum > 0);
- return (Datum)
- fastgetiattr(tuple, attNum, tupDesc, isNullOutP);
+ return (Datum)
+ fastgetiattr(tuple, attNum, tupDesc, isNullOutP);
}
RetrieveIndexResult
FormRetrieveIndexResult(ItemPointer indexItemPointer,
- ItemPointer heapItemPointer)
+ ItemPointer heapItemPointer)
{
- RetrieveIndexResult result;
-
- Assert(ItemPointerIsValid(indexItemPointer));
- Assert(ItemPointerIsValid(heapItemPointer));
-
- result = (RetrieveIndexResult) palloc(sizeof *result);
-
- result->index_iptr = *indexItemPointer;
- result->heap_iptr = *heapItemPointer;
-
- return (result);
+ RetrieveIndexResult result;
+
+ Assert(ItemPointerIsValid(indexItemPointer));
+ Assert(ItemPointerIsValid(heapItemPointer));
+
+ result = (RetrieveIndexResult) palloc(sizeof *result);
+
+ result->index_iptr = *indexItemPointer;
+ result->heap_iptr = *heapItemPointer;
+
+ return (result);
}
/*
@@ -425,19 +461,21 @@ FormRetrieveIndexResult(ItemPointer indexItemPointer,
*
* Change me if adding an attribute to IndexTuples!!!!!!!!!!!
*/
-static Size
+static Size
IndexInfoFindDataOffset(unsigned short t_info)
{
- if (!(t_info & INDEX_NULL_MASK))
- return((Size) sizeof(IndexTupleData));
- else {
- Size size = sizeof(IndexTupleData);
-
- if (t_info & INDEX_NULL_MASK) {
- size += sizeof(IndexAttributeBitMapData);
+ if (!(t_info & INDEX_NULL_MASK))
+ return ((Size) sizeof(IndexTupleData));
+ else
+ {
+ Size size = sizeof(IndexTupleData);
+
+ if (t_info & INDEX_NULL_MASK)
+ {
+ size += sizeof(IndexAttributeBitMapData);
+ }
+ return DOUBLEALIGN(size); /* be conservative */
}
- return DOUBLEALIGN(size); /* be conservative */
- }
}
/*
@@ -445,17 +483,17 @@ IndexInfoFindDataOffset(unsigned short t_info)
* we assume we have space that is already palloc'ed.
*/
void
-CopyIndexTuple(IndexTuple source, IndexTuple *target)
+CopyIndexTuple(IndexTuple source, IndexTuple * target)
{
- Size size;
- IndexTuple ret;
-
- size = IndexTupleSize(source);
- if (*target == NULL) {
- *target = (IndexTuple) palloc(size);
- }
-
- ret = *target;
- memmove((char*)ret, (char*)source, size);
-}
+ Size size;
+ IndexTuple ret;
+
+ size = IndexTupleSize(source);
+ if (*target == NULL)
+ {
+ *target = (IndexTuple) palloc(size);
+ }
+ ret = *target;
+ memmove((char *) ret, (char *) source, size);
+}
diff --git a/src/backend/access/common/indexvalid.c b/src/backend/access/common/indexvalid.c
index aff9af42f8..9f8501beb2 100644
--- a/src/backend/access/common/indexvalid.c
+++ b/src/backend/access/common/indexvalid.c
@@ -1,13 +1,13 @@
/*-------------------------------------------------------------------------
*
* indexvalid.c--
- * index tuple qualification validity checking code
+ * index tuple qualification validity checking code
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/Attic/indexvalid.c,v 1.14 1997/03/18 18:38:19 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/Attic/indexvalid.c,v 1.15 1997/09/07 04:37:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -21,64 +21,70 @@
#include <executor/execdebug.h>
/* ----------------------------------------------------------------
- * index scan key qualification code
+ * index scan key qualification code
* ----------------------------------------------------------------
*/
-int NIndexTupleProcessed;
+int NIndexTupleProcessed;
/* ----------------
- * index_keytest
+ * index_keytest
*
* old comments
- * May eventually combine with other tests (like timeranges)?
- * Should have Buffer buffer; as an argument and pass it to amgetattr.
+ * May eventually combine with other tests (like timeranges)?
+ * Should have Buffer buffer; as an argument and pass it to amgetattr.
* ----------------
*/
bool
index_keytest(IndexTuple tuple,
- TupleDesc tupdesc,
- int scanKeySize,
- ScanKey key)
+ TupleDesc tupdesc,
+ int scanKeySize,
+ ScanKey key)
{
- bool isNull;
- Datum datum;
- int test;
-
- IncrIndexProcessed();
-
- while (scanKeySize > 0) {
- datum = index_getattr(tuple,
- key[0].sk_attno,
- tupdesc,
- &isNull);
-
- if (isNull) {
- /* XXX eventually should check if SK_ISNULL */
- return (false);
- }
-
- if (key[0].sk_flags & SK_ISNULL) {
- return (false);
- }
+ bool isNull;
+ Datum datum;
+ int test;
- if (key[0].sk_flags & SK_COMMUTE) {
- test = (*(key[0].sk_func))
- (DatumGetPointer(key[0].sk_argument),
- datum) ? 1 : 0;
- } else {
- test = (*(key[0].sk_func))
- (datum,
- DatumGetPointer(key[0].sk_argument)) ? 1 : 0;
- }
-
- if (!test == !(key[0].sk_flags & SK_NEGATE)) {
- return (false);
+ IncrIndexProcessed();
+
+ while (scanKeySize > 0)
+ {
+ datum = index_getattr(tuple,
+ key[0].sk_attno,
+ tupdesc,
+ &isNull);
+
+ if (isNull)
+ {
+ /* XXX eventually should check if SK_ISNULL */
+ return (false);
+ }
+
+ if (key[0].sk_flags & SK_ISNULL)
+ {
+ return (false);
+ }
+
+ if (key[0].sk_flags & SK_COMMUTE)
+ {
+ test = (*(key[0].sk_func))
+ (DatumGetPointer(key[0].sk_argument),
+ datum) ? 1 : 0;
+ }
+ else
+ {
+ test = (*(key[0].sk_func))
+ (datum,
+ DatumGetPointer(key[0].sk_argument)) ? 1 : 0;
+ }
+
+ if (!test == !(key[0].sk_flags & SK_NEGATE))
+ {
+ return (false);
+ }
+
+ scanKeySize -= 1;
+ key++;
}
-
- scanKeySize -= 1;
- key++;
- }
-
- return (true);
-}
+ return (true);
+}
diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c
index 98fbddc639..599ac59a45 100644
--- a/src/backend/access/common/printtup.c
+++ b/src/backend/access/common/printtup.c
@@ -1,14 +1,14 @@
/*-------------------------------------------------------------------------
*
* printtup.c--
- * Routines to print out tuples to the destination (binary or non-binary
- * portals, frontend/interactive backend, etc.).
+ * Routines to print out tuples to the destination (binary or non-binary
+ * portals, frontend/interactive backend, etc.).
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.15 1997/08/26 23:31:23 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.16 1997/09/07 04:37:39 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -16,279 +16,304 @@
#include <string.h>
#include <postgres.h>
-#include <fmgr.h>
-#include <access/heapam.h>
-#include <access/printtup.h>
+#include <fmgr.h>
+#include <access/heapam.h>
+#include <access/printtup.h>
#include <catalog/pg_type.h>
#include <libpq/libpq.h>
#include <utils/syscache.h>
/* ----------------------------------------------------------------
- * printtup / debugtup support
+ * printtup / debugtup support
* ----------------------------------------------------------------
*/
/* ----------------
- * typtoout - used by printtup and debugtup
+ * typtoout - used by printtup and debugtup
* ----------------
*/
Oid
typtoout(Oid type)
{
- HeapTuple typeTuple;
-
- typeTuple = SearchSysCacheTuple(TYPOID,
- ObjectIdGetDatum(type),
- 0, 0, 0);
-
- if (HeapTupleIsValid(typeTuple))
- return((Oid)
- ((TypeTupleForm) GETSTRUCT(typeTuple))->typoutput);
-
- elog(WARN, "typtoout: Cache lookup of type %d failed", type);
- return(InvalidOid);
+ HeapTuple typeTuple;
+
+ typeTuple = SearchSysCacheTuple(TYPOID,
+ ObjectIdGetDatum(type),
+ 0, 0, 0);
+
+ if (HeapTupleIsValid(typeTuple))
+ return ((Oid)
+ ((TypeTupleForm) GETSTRUCT(typeTuple))->typoutput);
+
+ elog(WARN, "typtoout: Cache lookup of type %d failed", type);
+ return (InvalidOid);
}
Oid
gettypelem(Oid type)
{
- HeapTuple typeTuple;
-
- typeTuple = SearchSysCacheTuple(TYPOID,
- ObjectIdGetDatum(type),
- 0,0,0);
-
- if (HeapTupleIsValid(typeTuple))
- return((Oid)
- ((TypeTupleForm) GETSTRUCT(typeTuple))->typelem);
-
- elog(WARN, "typtoout: Cache lookup of type %d failed", type);
- return(InvalidOid);
+ HeapTuple typeTuple;
+
+ typeTuple = SearchSysCacheTuple(TYPOID,
+ ObjectIdGetDatum(type),
+ 0, 0, 0);
+
+ if (HeapTupleIsValid(typeTuple))
+ return ((Oid)
+ ((TypeTupleForm) GETSTRUCT(typeTuple))->typelem);
+
+ elog(WARN, "typtoout: Cache lookup of type %d failed", type);
+ return (InvalidOid);
}
/* ----------------
- * printtup
+ * printtup
* ----------------
*/
void
printtup(HeapTuple tuple, TupleDesc typeinfo)
{
- int i, j, k;
- char *outputstr, *attr;
- bool isnull;
- Oid typoutput;
-
- /* ----------------
- * tell the frontend to expect new tuple data
- * ----------------
- */
- pq_putnchar("D", 1);
-
- /* ----------------
- * send a bitmap of which attributes are null
- * ----------------
- */
- j = 0;
- k = 1 << 7;
- for (i = 0; i < tuple->t_natts; ) {
- i++; /* heap_getattr is a macro, so no increment */
- attr = heap_getattr(tuple, InvalidBuffer, i, typeinfo, &isnull);
- if (!isnull)
- j |= k;
- k >>= 1;
- if (!(i & 7)) {
- pq_putint(j, 1);
- j = 0;
- k = 1 << 7;
+ int i,
+ j,
+ k;
+ char *outputstr,
+ *attr;
+ bool isnull;
+ Oid typoutput;
+
+ /* ----------------
+ * tell the frontend to expect new tuple data
+ * ----------------
+ */
+ pq_putnchar("D", 1);
+
+ /* ----------------
+ * send a bitmap of which attributes are null
+ * ----------------
+ */
+ j = 0;
+ k = 1 << 7;
+ for (i = 0; i < tuple->t_natts;)
+ {
+ i++; /* heap_getattr is a macro, so no
+ * increment */
+ attr = heap_getattr(tuple, InvalidBuffer, i, typeinfo, &isnull);
+ if (!isnull)
+ j |= k;
+ k >>= 1;
+ if (!(i & 7))
+ {
+ pq_putint(j, 1);
+ j = 0;
+ k = 1 << 7;
+ }
}
- }
- if (i & 7)
- pq_putint(j, 1);
-
- /* ----------------
- * send the attributes of this tuple
- * ----------------
- */
- for (i = 0; i < tuple->t_natts; ++i) {
- attr = heap_getattr(tuple, InvalidBuffer, i+1, typeinfo, &isnull);
- typoutput = typtoout((Oid) typeinfo->attrs[i]->atttypid);
-
- if (!isnull && OidIsValid(typoutput)) {
- outputstr = fmgr(typoutput, attr,
- gettypelem(typeinfo->attrs[i]->atttypid));
- pq_putint(strlen(outputstr)+4, 4);
- pq_putnchar(outputstr, strlen(outputstr));
- pfree(outputstr);
+ if (i & 7)
+ pq_putint(j, 1);
+
+ /* ----------------
+ * send the attributes of this tuple
+ * ----------------
+ */
+ for (i = 0; i < tuple->t_natts; ++i)
+ {
+ attr = heap_getattr(tuple, InvalidBuffer, i + 1, typeinfo, &isnull);
+ typoutput = typtoout((Oid) typeinfo->attrs[i]->atttypid);
+
+ if (!isnull && OidIsValid(typoutput))
+ {
+ outputstr = fmgr(typoutput, attr,
+ gettypelem(typeinfo->attrs[i]->atttypid));
+ pq_putint(strlen(outputstr) + 4, 4);
+ pq_putnchar(outputstr, strlen(outputstr));
+ pfree(outputstr);
+ }
}
- }
}
/* ----------------
- * printatt
+ * printatt
* ----------------
*/
static void
printatt(unsigned attributeId,
- AttributeTupleForm attributeP,
- char *value)
+ AttributeTupleForm attributeP,
+ char *value)
{
- printf("\t%2d: %s%s%s%s\t(typeid = %u, len = %d, byval = %c)\n",
- attributeId,
- attributeP->attname.data,
- value != NULL ? " = \"" : "",
- value != NULL ? value : "",
- value != NULL ? "\"" : "",
- (unsigned int) (attributeP->atttypid),
- attributeP->attlen,
- attributeP->attbyval ? 't' : 'f');
+ printf("\t%2d: %s%s%s%s\t(typeid = %u, len = %d, byval = %c)\n",
+ attributeId,
+ attributeP->attname.data,
+ value != NULL ? " = \"" : "",
+ value != NULL ? value : "",
+ value != NULL ? "\"" : "",
+ (unsigned int) (attributeP->atttypid),
+ attributeP->attlen,
+ attributeP->attbyval ? 't' : 'f');
}
/* ----------------
- * showatts
+ * showatts
* ----------------
*/
void
showatts(char *name, TupleDesc tupleDesc)
{
- int i;
- int natts = tupleDesc->natts;
- AttributeTupleForm *attinfo = tupleDesc->attrs;
+ int i;
+ int natts = tupleDesc->natts;
+ AttributeTupleForm *attinfo = tupleDesc->attrs;
- puts(name);
- for (i = 0; i < natts; ++i)
- printatt((unsigned) i+1, attinfo[i], (char *) NULL);
- printf("\t----\n");
+ puts(name);
+ for (i = 0; i < natts; ++i)
+ printatt((unsigned) i + 1, attinfo[i], (char *) NULL);
+ printf("\t----\n");
}
/* ----------------
- * debugtup
+ * debugtup
* ----------------
*/
void
debugtup(HeapTuple tuple, TupleDesc typeinfo)
{
- register int i;
- char *attr, *value;
- bool isnull;
- Oid typoutput;
-
- for (i = 0; i < tuple->t_natts; ++i) {
- attr = heap_getattr(tuple, InvalidBuffer, i+1, typeinfo, &isnull);
- typoutput = typtoout((Oid) typeinfo->attrs[i]->atttypid);
-
- if (!isnull && OidIsValid(typoutput)) {
- value = fmgr(typoutput, attr,
- gettypelem(typeinfo->attrs[i]->atttypid));
- printatt((unsigned) i+1, typeinfo->attrs[i], value);
- pfree(value);
+ register int i;
+ char *attr,
+ *value;
+ bool isnull;
+ Oid typoutput;
+
+ for (i = 0; i < tuple->t_natts; ++i)
+ {
+ attr = heap_getattr(tuple, InvalidBuffer, i + 1, typeinfo, &isnull);
+ typoutput = typtoout((Oid) typeinfo->attrs[i]->atttypid);
+
+ if (!isnull && OidIsValid(typoutput))
+ {
+ value = fmgr(typoutput, attr,
+ gettypelem(typeinfo->attrs[i]->atttypid));
+ printatt((unsigned) i + 1, typeinfo->attrs[i], value);
+ pfree(value);
+ }
}
- }
- printf("\t----\n");
+ printf("\t----\n");
}
/* ----------------
- * printtup_internal
- * Protocol expects either T, D, C, E, or N.
- * We use a different data prefix, e.g. 'B' instead of 'D' to
- * indicate a tuple in internal (binary) form.
+ * printtup_internal
+ * Protocol expects either T, D, C, E, or N.
+ * We use a different data prefix, e.g. 'B' instead of 'D' to
+ * indicate a tuple in internal (binary) form.
*
- * This is same as printtup, except we don't use the typout func.
+ * This is same as printtup, except we don't use the typout func.
* ----------------
*/
void
printtup_internal(HeapTuple tuple, TupleDesc typeinfo)
{
- int i, j, k;
- char *attr;
- bool isnull;
-
- /* ----------------
- * tell the frontend to expect new tuple data
- * ----------------
- */
- pq_putnchar("B", 1);
-
- /* ----------------
- * send a bitmap of which attributes are null
- * ----------------
- */
- j = 0;
- k = 1 << 7;
- for (i = 0; i < tuple->t_natts; ) {
- i++; /* heap_getattr is a macro, so no increment */
- attr = heap_getattr(tuple, InvalidBuffer, i, typeinfo, &isnull);
- if (!isnull)
- j |= k;
- k >>= 1;
- if (!(i & 7)) {
- pq_putint(j, 1);
- j = 0;
- k = 1 << 7;
+ int i,
+ j,
+ k;
+ char *attr;
+ bool isnull;
+
+ /* ----------------
+ * tell the frontend to expect new tuple data
+ * ----------------
+ */
+ pq_putnchar("B", 1);
+
+ /* ----------------
+ * send a bitmap of which attributes are null
+ * ----------------
+ */
+ j = 0;
+ k = 1 << 7;
+ for (i = 0; i < tuple->t_natts;)
+ {
+ i++; /* heap_getattr is a macro, so no
+ * increment */
+ attr = heap_getattr(tuple, InvalidBuffer, i, typeinfo, &isnull);
+ if (!isnull)
+ j |= k;
+ k >>= 1;
+ if (!(i & 7))
+ {
+ pq_putint(j, 1);
+ j = 0;
+ k = 1 << 7;
+ }
}
- }
- if (i & 7)
- pq_putint(j, 1);
-
- /* ----------------
- * send the attributes of this tuple
- * ----------------
- */
+ if (i & 7)
+ pq_putint(j, 1);
+
+ /* ----------------
+ * send the attributes of this tuple
+ * ----------------
+ */
#ifdef IPORTAL_DEBUG
- fprintf(stderr, "sending tuple with %d atts\n", tuple->t_natts);
+ fprintf(stderr, "sending tuple with %d atts\n", tuple->t_natts);
#endif
- for (i = 0; i < tuple->t_natts; ++i) {
- int32 len = typeinfo->attrs[i]->attlen;
-
- attr = heap_getattr(tuple, InvalidBuffer, i+1, typeinfo, &isnull);
- if (!isnull) {
- /* # of bytes, and opaque data */
- if (len == -1) {
- /* variable length, assume a varlena structure */
- len = VARSIZE(attr) - VARHDRSZ;
-
- pq_putint(len, sizeof(int32));
- pq_putnchar(VARDATA(attr), len);
-#ifdef IPORTAL_DEBUG
+ for (i = 0; i < tuple->t_natts; ++i)
+ {
+ int32 len = typeinfo->attrs[i]->attlen;
+
+ attr = heap_getattr(tuple, InvalidBuffer, i + 1, typeinfo, &isnull);
+ if (!isnull)
{
- char *d = VARDATA(attr);
-
- fprintf(stderr, "length %d data %x%x%x%x\n",
- len, *d, *(d+1), *(d+2), *(d+3));
- }
+ /* # of bytes, and opaque data */
+ if (len == -1)
+ {
+ /* variable length, assume a varlena structure */
+ len = VARSIZE(attr) - VARHDRSZ;
+
+ pq_putint(len, sizeof(int32));
+ pq_putnchar(VARDATA(attr), len);
+#ifdef IPORTAL_DEBUG
+ {
+ char *d = VARDATA(attr);
+
+ fprintf(stderr, "length %d data %x%x%x%x\n",
+ len, *d, *(d + 1), *(d + 2), *(d + 3));
+ }
#endif
- } else {
- /* fixed size */
- if (typeinfo->attrs[i]->attbyval) {
- int8 i8;
- int16 i16;
- int32 i32;
-
- pq_putint(len, sizeof(int32));
- switch (len) {
- case sizeof(int8):
- i8 = DatumGetChar(attr);
- pq_putnchar((char *) &i8, len);
- break;
- case sizeof(int16):
- i16 = DatumGetInt16(attr);
- pq_putnchar((char *) &i16, len);
- break;
- case sizeof(int32):
- i32 = DatumGetInt32(attr);
- pq_putnchar((char *) &i32, len);
- break;
- }
+ }
+ else
+ {
+ /* fixed size */
+ if (typeinfo->attrs[i]->attbyval)
+ {
+ int8 i8;
+ int16 i16;
+ int32 i32;
+
+ pq_putint(len, sizeof(int32));
+ switch (len)
+ {
+ case sizeof(int8):
+ i8 = DatumGetChar(attr);
+ pq_putnchar((char *) &i8, len);
+ break;
+ case sizeof(int16):
+ i16 = DatumGetInt16(attr);
+ pq_putnchar((char *) &i16, len);
+ break;
+ case sizeof(int32):
+ i32 = DatumGetInt32(attr);
+ pq_putnchar((char *) &i32, len);
+ break;
+ }
#ifdef IPORTAL_DEBUG
- fprintf(stderr, "byval length %d data %d\n", len, attr);
+ fprintf(stderr, "byval length %d data %d\n", len, attr);
#endif
- } else {
- pq_putint(len, sizeof(int32));
- pq_putnchar(attr, len);
+ }
+ else
+ {
+ pq_putint(len, sizeof(int32));
+ pq_putnchar(attr, len);
#ifdef IPORTAL_DEBUG
- fprintf(stderr, "byref length %d data %x\n", len, attr);
+ fprintf(stderr, "byref length %d data %x\n", len, attr);
#endif
+ }
+ }
}
- }
}
- }
}
diff --git a/src/backend/access/common/scankey.c b/src/backend/access/common/scankey.c
index fb242497eb..9fbe264ae5 100644
--- a/src/backend/access/common/scankey.c
+++ b/src/backend/access/common/scankey.c
@@ -1,13 +1,13 @@
/*-------------------------------------------------------------------------
*
* scan.c--
- * scan direction and key code
+ * scan direction and key code
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/scankey.c,v 1.9 1996/11/05 07:42:45 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/scankey.c,v 1.10 1997/09/07 04:37:39 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -19,49 +19,49 @@
/*
* ScanKeyEntryIsLegal --
- * True iff the scan key entry is legal.
+ * True iff the scan key entry is legal.
*/
#define ScanKeyEntryIsLegal(entry) \
- ((bool) (AssertMacro(PointerIsValid(entry)) && \
- AttributeNumberIsValid(entry->sk_attno)))
+ ((bool) (AssertMacro(PointerIsValid(entry)) && \
+ AttributeNumberIsValid(entry->sk_attno)))
/*
* ScanKeyEntrySetIllegal --
- * Marks a scan key entry as illegal.
+ * Marks a scan key entry as illegal.
*/
void
ScanKeyEntrySetIllegal(ScanKey entry)
{
- Assert(PointerIsValid(entry));
-
- entry->sk_flags = 0; /* just in case... */
- entry->sk_attno = InvalidAttrNumber;
- entry->sk_procedure = 0; /* should be InvalidRegProcedure */
+ Assert(PointerIsValid(entry));
+
+ entry->sk_flags = 0; /* just in case... */
+ entry->sk_attno = InvalidAttrNumber;
+ entry->sk_procedure = 0; /* should be InvalidRegProcedure */
}
/*
* ScanKeyEntryInitialize --
- * Initializes an scan key entry.
+ * Initializes an scan key entry.
*
* Note:
- * Assumes the scan key entry is valid.
- * Assumes the intialized scan key entry will be legal.
+ * Assumes the scan key entry is valid.
+ * Assumes the intialized scan key entry will be legal.
*/
void
ScanKeyEntryInitialize(ScanKey entry,
- bits16 flags,
- AttrNumber attributeNumber,
- RegProcedure procedure,
- Datum argument)
+ bits16 flags,
+ AttrNumber attributeNumber,
+ RegProcedure procedure,
+ Datum argument)
{
- Assert(PointerIsValid(entry));
-
- entry->sk_flags = flags;
- entry->sk_attno = attributeNumber;
- entry->sk_procedure = procedure;
- entry->sk_argument = argument;
- fmgr_info(procedure, &entry->sk_func, &entry->sk_nargs);
-
- Assert(ScanKeyEntryIsLegal(entry));
+ Assert(PointerIsValid(entry));
+
+ entry->sk_flags = flags;
+ entry->sk_attno = attributeNumber;
+ entry->sk_procedure = procedure;
+ entry->sk_argument = argument;
+ fmgr_info(procedure, &entry->sk_func, &entry->sk_nargs);
+
+ Assert(ScanKeyEntryIsLegal(entry));
}
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index a38a5229f2..e616702a8e 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -1,17 +1,17 @@
/*-------------------------------------------------------------------------
*
* tupdesc.c--
- * POSTGRES tuple descriptor support code
+ * POSTGRES tuple descriptor support code
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.19 1997/08/22 02:55:39 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.20 1997/09/07 04:37:41 momjian Exp $
*
* NOTES
- * some of the executor utility code such as "ExecTypeFromTL" should be
- * moved here.
+ * some of the executor utility code such as "ExecTypeFromTL" should be
+ * moved here.
*
*-------------------------------------------------------------------------
*/
@@ -28,518 +28,534 @@
#include <utils/syscache.h>
#ifndef HAVE_MEMMOVE
-# include <regex/utils.h>
+#include <regex/utils.h>
#else
-# include <string.h>
+#include <string.h>
#endif
/* ----------------------------------------------------------------
- * CreateTemplateTupleDesc
+ * CreateTemplateTupleDesc
*
- * This function allocates and zeros a tuple descriptor structure.
+ * This function allocates and zeros a tuple descriptor structure.
* ----------------------------------------------------------------
*/
TupleDesc
CreateTemplateTupleDesc(int natts)
{
- uint32 size;
- TupleDesc desc;
-
- /* ----------------
- * sanity checks
- * ----------------
- */
- AssertArg(natts >= 1);
-
- /* ----------------
- * allocate enough memory for the tuple descriptor and
- * zero it as TupleDescInitEntry assumes that the descriptor
- * is filled with NULL pointers.
- * ----------------
- */
- size = natts * sizeof (AttributeTupleForm);
- desc = (TupleDesc) palloc(sizeof(struct tupleDesc));
- desc->attrs = (AttributeTupleForm*) palloc(size);
- desc->constr = NULL;
- memset(desc->attrs, 0, size);
-
- desc->natts = natts;
-
- return (desc);
+ uint32 size;
+ TupleDesc desc;
+
+ /* ----------------
+ * sanity checks
+ * ----------------
+ */
+ AssertArg(natts >= 1);
+
+ /* ----------------
+ * allocate enough memory for the tuple descriptor and
+ * zero it as TupleDescInitEntry assumes that the descriptor
+ * is filled with NULL pointers.
+ * ----------------
+ */
+ size = natts * sizeof(AttributeTupleForm);
+ desc = (TupleDesc) palloc(sizeof(struct tupleDesc));
+ desc->attrs = (AttributeTupleForm *) palloc(size);
+ desc->constr = NULL;
+ memset(desc->attrs, 0, size);
+
+ desc->natts = natts;
+
+ return (desc);
}
/* ----------------------------------------------------------------
- * CreateTupleDesc
+ * CreateTupleDesc
*
- * This function allocates a new TupleDesc from AttributeTupleForm array
+ * This function allocates a new TupleDesc from AttributeTupleForm array
* ----------------------------------------------------------------
*/
TupleDesc
-CreateTupleDesc(int natts, AttributeTupleForm* attrs)
+CreateTupleDesc(int natts, AttributeTupleForm * attrs)
{
- TupleDesc desc;
-
- /* ----------------
- * sanity checks
- * ----------------
- */
- AssertArg(natts >= 1);
-
- desc = (TupleDesc) palloc(sizeof(struct tupleDesc));
- desc->attrs = attrs;
- desc->natts = natts;
- desc->constr = NULL;
-
- return (desc);
+ TupleDesc desc;
+
+ /* ----------------
+ * sanity checks
+ * ----------------
+ */
+ AssertArg(natts >= 1);
+
+ desc = (TupleDesc) palloc(sizeof(struct tupleDesc));
+ desc->attrs = attrs;
+ desc->natts = natts;
+ desc->constr = NULL;
+
+ return (desc);
}
/* ----------------------------------------------------------------
- * CreateTupleDescCopy
+ * CreateTupleDescCopy
*
- * This function creates a new TupleDesc by copying from an existing
- * TupleDesc
- *
- * !!! Constraints are not copied !!!
+ * This function creates a new TupleDesc by copying from an existing
+ * TupleDesc
+ *
+ * !!! Constraints are not copied !!!
* ----------------------------------------------------------------
*/
TupleDesc
CreateTupleDescCopy(TupleDesc tupdesc)
{
- TupleDesc desc;
- int i, size;
-
- desc = (TupleDesc) palloc(sizeof(struct tupleDesc));
- desc->natts = tupdesc->natts;
- size = desc->natts * sizeof (AttributeTupleForm);
- desc->attrs = (AttributeTupleForm*) palloc(size);
- for (i=0;i<desc->natts;i++) {
- desc->attrs[i] =
- (AttributeTupleForm)palloc(ATTRIBUTE_TUPLE_SIZE);
- memmove(desc->attrs[i],
- tupdesc->attrs[i],
- ATTRIBUTE_TUPLE_SIZE);
- desc->attrs[i]->attnotnull = false;
- desc->attrs[i]->atthasdef = false;
- }
- desc->constr = NULL;
-
- return desc;
+ TupleDesc desc;
+ int i,
+ size;
+
+ desc = (TupleDesc) palloc(sizeof(struct tupleDesc));
+ desc->natts = tupdesc->natts;
+ size = desc->natts * sizeof(AttributeTupleForm);
+ desc->attrs = (AttributeTupleForm *) palloc(size);
+ for (i = 0; i < desc->natts; i++)
+ {
+ desc->attrs[i] =
+ (AttributeTupleForm) palloc(ATTRIBUTE_TUPLE_SIZE);
+ memmove(desc->attrs[i],
+ tupdesc->attrs[i],
+ ATTRIBUTE_TUPLE_SIZE);
+ desc->attrs[i]->attnotnull = false;
+ desc->attrs[i]->atthasdef = false;
+ }
+ desc->constr = NULL;
+
+ return desc;
}
/* ----------------------------------------------------------------
- * CreateTupleDescCopyConstr
+ * CreateTupleDescCopyConstr
+ *
+ * This function creates a new TupleDesc by copying from an existing
+ * TupleDesc (with Constraints)
*
- * This function creates a new TupleDesc by copying from an existing
- * TupleDesc (with Constraints)
- *
* ----------------------------------------------------------------
*/
TupleDesc
CreateTupleDescCopyConstr(TupleDesc tupdesc)
{
- TupleDesc desc;
- TupleConstr *constr = tupdesc->constr;
- int i, size;
-
- desc = (TupleDesc) palloc(sizeof(struct tupleDesc));
- desc->natts = tupdesc->natts;
- size = desc->natts * sizeof (AttributeTupleForm);
- desc->attrs = (AttributeTupleForm*) palloc(size);
- for (i=0;i<desc->natts;i++) {
- desc->attrs[i] =
- (AttributeTupleForm)palloc(ATTRIBUTE_TUPLE_SIZE);
- memmove(desc->attrs[i],
- tupdesc->attrs[i],
- ATTRIBUTE_TUPLE_SIZE);
- }
- if (constr)
- {
- TupleConstr *cpy = (TupleConstr *) palloc(sizeof(TupleConstr));
-
- cpy->has_not_null = constr->has_not_null;
-
- if ( ( cpy->num_defval = constr->num_defval ) > 0 )
- {
- cpy->defval = (AttrDefault *) palloc (cpy->num_defval * sizeof (AttrDefault));
- memcpy (cpy->defval, constr->defval, cpy->num_defval * sizeof (AttrDefault));
- for (i = cpy->num_defval - 1; i >= 0; i--)
- {
- if ( constr->defval[i].adbin )
- cpy->defval[i].adbin = pstrdup (constr->defval[i].adbin);
- if ( constr->defval[i].adsrc )
- cpy->defval[i].adsrc = pstrdup (constr->defval[i].adsrc);
- }
- }
-
- if ( ( cpy->num_check = constr->num_check ) > 0 )
- {
- cpy->check = (ConstrCheck *) palloc (cpy->num_check * sizeof (ConstrCheck));
- memcpy (cpy->check, constr->check, cpy->num_check * sizeof (ConstrCheck));
- for (i = cpy->num_check - 1; i >= 0; i--)
- {
- if ( constr->check[i].ccname )
- cpy->check[i].ccname = pstrdup (constr->check[i].ccname);
- if ( constr->check[i].ccbin )
- cpy->check[i].ccbin = pstrdup (constr->check[i].ccbin);
- if ( constr->check[i].ccsrc )
- cpy->check[i].ccsrc = pstrdup (constr->check[i].ccsrc);
- }
- }
-
- desc->constr = cpy;
- }
- else
- desc->constr = NULL;
-
- return desc;
+ TupleDesc desc;
+ TupleConstr *constr = tupdesc->constr;
+ int i,
+ size;
+
+ desc = (TupleDesc) palloc(sizeof(struct tupleDesc));
+ desc->natts = tupdesc->natts;
+ size = desc->natts * sizeof(AttributeTupleForm);
+ desc->attrs = (AttributeTupleForm *) palloc(size);
+ for (i = 0; i < desc->natts; i++)
+ {
+ desc->attrs[i] =
+ (AttributeTupleForm) palloc(ATTRIBUTE_TUPLE_SIZE);
+ memmove(desc->attrs[i],
+ tupdesc->attrs[i],
+ ATTRIBUTE_TUPLE_SIZE);
+ }
+ if (constr)
+ {
+ TupleConstr *cpy = (TupleConstr *) palloc(sizeof(TupleConstr));
+
+ cpy->has_not_null = constr->has_not_null;
+
+ if ((cpy->num_defval = constr->num_defval) > 0)
+ {
+ cpy->defval = (AttrDefault *) palloc(cpy->num_defval * sizeof(AttrDefault));
+ memcpy(cpy->defval, constr->defval, cpy->num_defval * sizeof(AttrDefault));
+ for (i = cpy->num_defval - 1; i >= 0; i--)
+ {
+ if (constr->defval[i].adbin)
+ cpy->defval[i].adbin = pstrdup(constr->defval[i].adbin);
+ if (constr->defval[i].adsrc)
+ cpy->defval[i].adsrc = pstrdup(constr->defval[i].adsrc);
+ }
+ }
+
+ if ((cpy->num_check = constr->num_check) > 0)
+ {
+ cpy->check = (ConstrCheck *) palloc(cpy->num_check * sizeof(ConstrCheck));
+ memcpy(cpy->check, constr->check, cpy->num_check * sizeof(ConstrCheck));
+ for (i = cpy->num_check - 1; i >= 0; i--)
+ {
+ if (constr->check[i].ccname)
+ cpy->check[i].ccname = pstrdup(constr->check[i].ccname);
+ if (constr->check[i].ccbin)
+ cpy->check[i].ccbin = pstrdup(constr->check[i].ccbin);
+ if (constr->check[i].ccsrc)
+ cpy->check[i].ccsrc = pstrdup(constr->check[i].ccsrc);
+ }
+ }
+
+ desc->constr = cpy;
+ }
+ else
+ desc->constr = NULL;
+
+ return desc;
}
void
-FreeTupleDesc (TupleDesc tupdesc)
+FreeTupleDesc(TupleDesc tupdesc)
{
- int i;
-
- for (i = 0; i < tupdesc->natts; i++)
- pfree (tupdesc->attrs[i]);
- pfree (tupdesc->attrs);
- if ( tupdesc->constr )
- {
- if ( tupdesc->constr->num_defval > 0 )
- {
- AttrDefault *attrdef = tupdesc->constr->defval;
-
- for (i = tupdesc->constr->num_defval - 1; i >= 0; i--)
- {
- if ( attrdef[i].adbin )
- pfree (attrdef[i].adbin);
- if ( attrdef[i].adsrc )
- pfree (attrdef[i].adsrc);
- }
- pfree (attrdef);
- }
- if ( tupdesc->constr->num_check > 0 )
- {
- ConstrCheck *check = tupdesc->constr->check;
-
- for (i = tupdesc->constr->num_check - 1; i >= 0; i--)
- {
- if ( check[i].ccname )
- pfree (check[i].ccname);
- if ( check[i].ccbin )
- pfree (check[i].ccbin);
- if ( check[i].ccsrc )
- pfree (check[i].ccsrc);
- }
- pfree (check);
- }
- pfree (tupdesc->constr);
- }
-
- pfree (tupdesc);
+ int i;
+
+ for (i = 0; i < tupdesc->natts; i++)
+ pfree(tupdesc->attrs[i]);
+ pfree(tupdesc->attrs);
+ if (tupdesc->constr)
+ {
+ if (tupdesc->constr->num_defval > 0)
+ {
+ AttrDefault *attrdef = tupdesc->constr->defval;
+
+ for (i = tupdesc->constr->num_defval - 1; i >= 0; i--)
+ {
+ if (attrdef[i].adbin)
+ pfree(attrdef[i].adbin);
+ if (attrdef[i].adsrc)
+ pfree(attrdef[i].adsrc);
+ }
+ pfree(attrdef);
+ }
+ if (tupdesc->constr->num_check > 0)
+ {
+ ConstrCheck *check = tupdesc->constr->check;
+
+ for (i = tupdesc->constr->num_check - 1; i >= 0; i--)
+ {
+ if (check[i].ccname)
+ pfree(check[i].ccname);
+ if (check[i].ccbin)
+ pfree(check[i].ccbin);
+ if (check[i].ccsrc)
+ pfree(check[i].ccsrc);
+ }
+ pfree(check);
+ }
+ pfree(tupdesc->constr);
+ }
+
+ pfree(tupdesc);
}
/* ----------------------------------------------------------------
- * TupleDescInitEntry
+ * TupleDescInitEntry
*
- * This function initializes a single attribute structure in
- * a preallocated tuple descriptor.
+ * This function initializes a single attribute structure in
+ * a preallocated tuple descriptor.
* ----------------------------------------------------------------
*/
bool
TupleDescInitEntry(TupleDesc desc,
- AttrNumber attributeNumber,
- char *attributeName,
- char *typeName,
- int attdim,
- bool attisset)
+ AttrNumber attributeNumber,
+ char *attributeName,
+ char *typeName,
+ int attdim,
+ bool attisset)
{
- HeapTuple tuple;
- TypeTupleForm typeForm;
- AttributeTupleForm att;
-
- /* ----------------
- * sanity checks
- * ----------------
- */
- AssertArg(PointerIsValid(desc));
- AssertArg(attributeNumber >= 1);
- /* attributeName's are sometimes NULL,
- from resdom's. I don't know why that is, though -- Jolly */
-/* AssertArg(NameIsValid(attributeName));*/
-/* AssertArg(NameIsValid(typeName));*/
-
- AssertArg(!PointerIsValid(desc->attrs[attributeNumber - 1]));
-
-
- /* ----------------
- * allocate storage for this attribute
- * ----------------
- */
-
- att = (AttributeTupleForm) palloc(ATTRIBUTE_TUPLE_SIZE);
- desc->attrs[attributeNumber - 1] = att;
-
- /* ----------------
- * initialize some of the attribute fields
- * ----------------
- */
- att->attrelid = 0; /* dummy value */
-
- if (attributeName != NULL)
- namestrcpy(&(att->attname), attributeName);
- else
- memset(att->attname.data,0,NAMEDATALEN);
-
-
- att->attdisbursion = 0; /* dummy value */
- att->attcacheoff = -1;
-
- att->attnum = attributeNumber;
- att->attnelems = attdim;
- att->attisset = attisset;
-
- att->attnotnull = false;
- att->atthasdef = false;
-
- /* ----------------
- * search the system cache for the type tuple of the attribute
- * we are creating so that we can get the typeid and some other
- * stuff.
- *
- * Note: in the special case of
- *
- * create EMP (name = char16, manager = EMP)
- *
- * RelationNameCreateHeapRelation() calls BuildDesc() which
- * calls this routine and since EMP does not exist yet, the
- * system cache lookup below fails. That's fine, but rather
- * then doing a elog(WARN) we just leave that information
- * uninitialized, return false, then fix things up later.
- * -cim 6/14/90
- * ----------------
- */
- tuple = SearchSysCacheTuple(TYPNAME, PointerGetDatum(typeName),
- 0,0,0);
- if (! HeapTupleIsValid(tuple)) {
+ HeapTuple tuple;
+ TypeTupleForm typeForm;
+ AttributeTupleForm att;
+
/* ----------------
- * here type info does not exist yet so we just fill
- * the attribute with dummy information and return false.
+ * sanity checks
* ----------------
*/
- att->atttypid = InvalidOid;
- att->attlen = (int16) 0;
- att->attbyval = (bool) 0;
- att->attalign = 'i';
- return false;
- }
-
- /* ----------------
- * type info exists so we initialize our attribute
- * information from the type tuple we found..
- * ----------------
- */
- typeForm = (TypeTupleForm) GETSTRUCT(tuple);
-
- att->atttypid = tuple->t_oid;
- att->attalign = typeForm->typalign;
-
- /* ------------------------
- If this attribute is a set, what is really stored in the
- attribute is the OID of a tuple in the pg_proc catalog.
- The pg_proc tuple contains the query string which defines
- this set - i.e., the query to run to get the set.
- So the atttypid (just assigned above) refers to the type returned
- by this query, but the actual length of this attribute is the
- length (size) of an OID.
-
- Why not just make the atttypid point to the OID type, instead
- of the type the query returns? Because the executor uses the atttypid
- to tell the front end what type will be returned (in BeginCommand),
- and in the end the type returned will be the result of the query, not
- an OID.
-
- Why not wait until the return type of the set is known (i.e., the
- recursive call to the executor to execute the set has returned)
- before telling the front end what the return type will be? Because
- the executor is a delicate thing, and making sure that the correct
- order of front-end commands is maintained is messy, especially
- considering that target lists may change as inherited attributes
- are considered, etc. Ugh.
- -----------------------------------------
- */
- if (attisset) {
- Type t = type("oid");
- att->attlen = tlen(t);
- att->attbyval = tbyval(t);
- } else {
- att->attlen = typeForm->typlen;
- att->attbyval = typeForm->typbyval;
- }
-
-
- return true;
+ AssertArg(PointerIsValid(desc));
+ AssertArg(attributeNumber >= 1);
+
+ /*
+ * attributeName's are sometimes NULL, from resdom's. I don't know
+ * why that is, though -- Jolly
+ */
+/* AssertArg(NameIsValid(attributeName));*/
+/* AssertArg(NameIsValid(typeName));*/
+
+ AssertArg(!PointerIsValid(desc->attrs[attributeNumber - 1]));
+
+
+ /* ----------------
+ * allocate storage for this attribute
+ * ----------------
+ */
+
+ att = (AttributeTupleForm) palloc(ATTRIBUTE_TUPLE_SIZE);
+ desc->attrs[attributeNumber - 1] = att;
+
+ /* ----------------
+ * initialize some of the attribute fields
+ * ----------------
+ */
+ att->attrelid = 0; /* dummy value */
+
+ if (attributeName != NULL)
+ namestrcpy(&(att->attname), attributeName);
+ else
+ memset(att->attname.data, 0, NAMEDATALEN);
+
+
+ att->attdisbursion = 0; /* dummy value */
+ att->attcacheoff = -1;
+
+ att->attnum = attributeNumber;
+ att->attnelems = attdim;
+ att->attisset = attisset;
+
+ att->attnotnull = false;
+ att->atthasdef = false;
+
+ /* ----------------
+ * search the system cache for the type tuple of the attribute
+ * we are creating so that we can get the typeid and some other
+ * stuff.
+ *
+ * Note: in the special case of
+ *
+ * create EMP (name = char16, manager = EMP)
+ *
+ * RelationNameCreateHeapRelation() calls BuildDesc() which
+ * calls this routine and since EMP does not exist yet, the
+ * system cache lookup below fails. That's fine, but rather
+ * then doing a elog(WARN) we just leave that information
+ * uninitialized, return false, then fix things up later.
+ * -cim 6/14/90
+ * ----------------
+ */
+ tuple = SearchSysCacheTuple(TYPNAME, PointerGetDatum(typeName),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tuple))
+ {
+ /* ----------------
+ * here type info does not exist yet so we just fill
+ * the attribute with dummy information and return false.
+ * ----------------
+ */
+ att->atttypid = InvalidOid;
+ att->attlen = (int16) 0;
+ att->attbyval = (bool) 0;
+ att->attalign = 'i';
+ return false;
+ }
+
+ /* ----------------
+ * type info exists so we initialize our attribute
+ * information from the type tuple we found..
+ * ----------------
+ */
+ typeForm = (TypeTupleForm) GETSTRUCT(tuple);
+
+ att->atttypid = tuple->t_oid;
+ att->attalign = typeForm->typalign;
+
+ /* ------------------------
+ If this attribute is a set, what is really stored in the
+ attribute is the OID of a tuple in the pg_proc catalog.
+ The pg_proc tuple contains the query string which defines
+ this set - i.e., the query to run to get the set.
+ So the atttypid (just assigned above) refers to the type returned
+ by this query, but the actual length of this attribute is the
+ length (size) of an OID.
+
+ Why not just make the atttypid point to the OID type, instead
+ of the type the query returns? Because the executor uses the atttypid
+ to tell the front end what type will be returned (in BeginCommand),
+ and in the end the type returned will be the result of the query, not
+ an OID.
+
+ Why not wait until the return type of the set is known (i.e., the
+ recursive call to the executor to execute the set has returned)
+ before telling the front end what the return type will be? Because
+ the executor is a delicate thing, and making sure that the correct
+ order of front-end commands is maintained is messy, especially
+ considering that target lists may change as inherited attributes
+ are considered, etc. Ugh.
+ -----------------------------------------
+ */
+ if (attisset)
+ {
+ Type t = type("oid");
+
+ att->attlen = tlen(t);
+ att->attbyval = tbyval(t);
+ }
+ else
+ {
+ att->attlen = typeForm->typlen;
+ att->attbyval = typeForm->typbyval;
+ }
+
+
+ return true;
}
/* ----------------------------------------------------------------
- * TupleDescMakeSelfReference
+ * TupleDescMakeSelfReference
*
- * This function initializes a "self-referential" attribute like
- * manager in "create EMP (name=text, manager = EMP)".
- * It calls TypeShellMake() which inserts a "shell" type
- * tuple into pg_type. A self-reference is one kind of set, so
- * its size and byval are the same as for a set. See the comments
- * above in TupleDescInitEntry.
+ * This function initializes a "self-referential" attribute like
+ * manager in "create EMP (name=text, manager = EMP)".
+ * It calls TypeShellMake() which inserts a "shell" type
+ * tuple into pg_type. A self-reference is one kind of set, so
+ * its size and byval are the same as for a set. See the comments
+ * above in TupleDescInitEntry.
* ----------------------------------------------------------------
*/
static void
TupleDescMakeSelfReference(TupleDesc desc,
- AttrNumber attnum,
- char *relname)
+ AttrNumber attnum,
+ char *relname)
{
- AttributeTupleForm att;
- Type t = type("oid");
-
- att = desc->attrs[attnum-1];
- att->atttypid = TypeShellMake(relname);
- att->attlen = tlen(t);
- att->attbyval = tbyval(t);
- att->attnelems = 0;
+ AttributeTupleForm att;
+ Type t = type("oid");
+
+ att = desc->attrs[attnum - 1];
+ att->atttypid = TypeShellMake(relname);
+ att->attlen = tlen(t);
+ att->attbyval = tbyval(t);
+ att->attnelems = 0;
}
/* ----------------------------------------------------------------
- * BuildDescForRelation
+ * BuildDescForRelation
*
- * This is a general purpose function identical to BuildDesc
- * but is used by the DefineRelation() code to catch the
- * special case where you
+ * This is a general purpose function identical to BuildDesc
+ * but is used by the DefineRelation() code to catch the
+ * special case where you
*
- * create FOO ( ..., x = FOO )
+ * create FOO ( ..., x = FOO )
*
- * here, the initial type lookup for "x = FOO" will fail
- * because FOO isn't in the catalogs yet. But since we
- * are creating FOO, instead of doing an elog() we add
- * a shell type tuple to pg_type and fix things later
- * in amcreate().
+ * here, the initial type lookup for "x = FOO" will fail
+ * because FOO isn't in the catalogs yet. But since we
+ * are creating FOO, instead of doing an elog() we add
+ * a shell type tuple to pg_type and fix things later
+ * in amcreate().
* ----------------------------------------------------------------
*/
TupleDesc
-BuildDescForRelation(List *schema, char *relname)
+BuildDescForRelation(List * schema, char *relname)
{
- int natts;
- AttrNumber attnum;
- List *p;
- TupleDesc desc;
- AttrDefault *attrdef = NULL;
- TupleConstr *constr = (TupleConstr *) palloc(sizeof(TupleConstr));
- char *attname;
- char *typename;
- int attdim;
- int ndef = 0;
- bool attisset;
-
- /* ----------------
- * allocate a new tuple descriptor
- * ----------------
- */
- natts = length(schema);
- desc = CreateTemplateTupleDesc(natts);
- constr->has_not_null = false;
-
- attnum = 0;
-
- typename = palloc(NAMEDATALEN);
-
- foreach(p, schema) {
- ColumnDef *entry;
- List *arry;
+ int natts;
+ AttrNumber attnum;
+ List *p;
+ TupleDesc desc;
+ AttrDefault *attrdef = NULL;
+ TupleConstr *constr = (TupleConstr *) palloc(sizeof(TupleConstr));
+ char *attname;
+ char *typename;
+ int attdim;
+ int ndef = 0;
+ bool attisset;
/* ----------------
- * for each entry in the list, get the name and type
- * information from the list and have TupleDescInitEntry
- * fill in the attribute information we need.
+ * allocate a new tuple descriptor
* ----------------
- */
- attnum++;
-
- entry = lfirst(p);
- attname = entry->colname;
- arry = entry->typename->arrayBounds;
- attisset = entry->typename->setof;
-
- strNcpy(typename, entry->typename->name,NAMEDATALEN-1);
- if (arry != NIL)
- attdim = length(arry);
- else
- attdim = 0;
-
- if (! TupleDescInitEntry(desc, attnum, attname,
- typename, attdim, attisset)) {
- /* ----------------
- * if TupleDescInitEntry() fails, it means there is
- * no type in the system catalogs. So now we check if
- * the type name equals the relation name. If so we
- * have a self reference, otherwise it's an error.
- * ----------------
- */
- if (!strcmp(typename, relname)) {
- TupleDescMakeSelfReference(desc, attnum, relname);
- } else
- elog(WARN, "DefineRelation: no such type %s",
- typename);
- }
-
- /*
- * this is for char() and varchar(). When an entry is of type
- * char() or varchar(), typlen is set to the appropriate length,
- * which we'll use here instead. (The catalog lookup only returns
- * the length of bpchar and varchar which is not what we want!)
- * - ay 6/95
*/
- if (entry->typename->typlen > 0) {
- desc->attrs[attnum - 1]->attlen = entry->typename->typlen;
- }
+ natts = length(schema);
+ desc = CreateTemplateTupleDesc(natts);
+ constr->has_not_null = false;
- /* This is for constraints */
- if (entry->is_not_null)
- constr->has_not_null = true;
- desc->attrs[attnum-1]->attnotnull = entry->is_not_null;
-
- if ( entry->defval != NULL )
+ attnum = 0;
+
+ typename = palloc(NAMEDATALEN);
+
+ foreach(p, schema)
{
- if ( attrdef == NULL )
- attrdef = (AttrDefault*) palloc (natts * sizeof (AttrDefault));
- attrdef[ndef].adnum = attnum;
- attrdef[ndef].adbin = NULL;
- attrdef[ndef].adsrc = entry->defval;
- ndef++;
- desc->attrs[attnum-1]->atthasdef = true;
+ ColumnDef *entry;
+ List *arry;
+
+ /* ----------------
+ * for each entry in the list, get the name and type
+ * information from the list and have TupleDescInitEntry
+ * fill in the attribute information we need.
+ * ----------------
+ */
+ attnum++;
+
+ entry = lfirst(p);
+ attname = entry->colname;
+ arry = entry->typename->arrayBounds;
+ attisset = entry->typename->setof;
+
+ strNcpy(typename, entry->typename->name, NAMEDATALEN - 1);
+ if (arry != NIL)
+ attdim = length(arry);
+ else
+ attdim = 0;
+
+ if (!TupleDescInitEntry(desc, attnum, attname,
+ typename, attdim, attisset))
+ {
+ /* ----------------
+ * if TupleDescInitEntry() fails, it means there is
+ * no type in the system catalogs. So now we check if
+ * the type name equals the relation name. If so we
+ * have a self reference, otherwise it's an error.
+ * ----------------
+ */
+ if (!strcmp(typename, relname))
+ {
+ TupleDescMakeSelfReference(desc, attnum, relname);
+ }
+ else
+ elog(WARN, "DefineRelation: no such type %s",
+ typename);
+ }
+
+ /*
+ * this is for char() and varchar(). When an entry is of type
+ * char() or varchar(), typlen is set to the appropriate length,
+ * which we'll use here instead. (The catalog lookup only returns
+ * the length of bpchar and varchar which is not what we want!) -
+ * ay 6/95
+ */
+ if (entry->typename->typlen > 0)
+ {
+ desc->attrs[attnum - 1]->attlen = entry->typename->typlen;
+ }
+
+ /* This is for constraints */
+ if (entry->is_not_null)
+ constr->has_not_null = true;
+ desc->attrs[attnum - 1]->attnotnull = entry->is_not_null;
+
+ if (entry->defval != NULL)
+ {
+ if (attrdef == NULL)
+ attrdef = (AttrDefault *) palloc(natts * sizeof(AttrDefault));
+ attrdef[ndef].adnum = attnum;
+ attrdef[ndef].adbin = NULL;
+ attrdef[ndef].adsrc = entry->defval;
+ ndef++;
+ desc->attrs[attnum - 1]->atthasdef = true;
+ }
+
}
+ if (constr->has_not_null || ndef > 0)
+ {
+ desc->constr = constr;
- }
- if ( constr->has_not_null || ndef > 0 )
- {
- desc->constr = constr;
-
- if ( ndef > 0 ) /* DEFAULTs */
- {
- if ( ndef < natts )
- constr->defval = (AttrDefault*)
- repalloc (attrdef, ndef * sizeof (AttrDefault));
- else
- constr->defval = attrdef;
- constr->num_defval = ndef;
- }
- else
- constr->num_defval = 0;
- constr->num_check = 0;
- }
- else
- {
- pfree (constr);
- desc->constr = NULL;
- }
- return desc;
+ if (ndef > 0) /* DEFAULTs */
+ {
+ if (ndef < natts)
+ constr->defval = (AttrDefault *)
+ repalloc(attrdef, ndef * sizeof(AttrDefault));
+ else
+ constr->defval = attrdef;
+ constr->num_defval = ndef;
+ }
+ else
+ constr->num_defval = 0;
+ constr->num_check = 0;
+ }
+ else
+ {
+ pfree(constr);
+ desc->constr = NULL;
+ }
+ return desc;
}
-
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 1d36f340ed..598f9ed8f0 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -1,7 +1,7 @@
/*-------------------------------------------------------------------------
*
* gist.c--
- * interface routines for the postgres GiST index access method.
+ * interface routines for the postgres GiST index access method.
*
*
*
@@ -26,308 +26,345 @@
#include <utils/syscache.h>
#ifndef HAVE_MEMMOVE
-# include <regex/utils.h>
+#include <regex/utils.h>
#else
-# include <string.h>
+#include <string.h>
#endif
/* non-export function prototypes */
-static InsertIndexResult gistdoinsert(Relation r, IndexTuple itup,
- GISTSTATE *GISTstate);
-static InsertIndexResult gistentryinsert(Relation r, GISTSTACK *stk,
- IndexTuple tup,
- GISTSTATE *giststate);
-static void gistentryinserttwo(Relation r, GISTSTACK *stk, IndexTuple ltup,
- IndexTuple rtup, GISTSTATE *giststate);
-static void gistAdjustKeys(Relation r, GISTSTACK *stk, BlockNumber blk,
- char *datum, int att_size, GISTSTATE *giststate);
-static void gistintinsert(Relation r, GISTSTACK *stk, IndexTuple ltup,
- IndexTuple rtup, GISTSTATE *giststate);
-static InsertIndexResult gistSplit(Relation r, Buffer buffer,
- GISTSTACK *stack, IndexTuple itup,
- GISTSTATE *giststate);
-static void gistnewroot(GISTSTATE *giststate, Relation r, IndexTuple lt,
+static InsertIndexResult
+gistdoinsert(Relation r, IndexTuple itup,
+ GISTSTATE * GISTstate);
+static InsertIndexResult
+gistentryinsert(Relation r, GISTSTACK * stk,
+ IndexTuple tup,
+ GISTSTATE * giststate);
+static void
+gistentryinserttwo(Relation r, GISTSTACK * stk, IndexTuple ltup,
+ IndexTuple rtup, GISTSTATE * giststate);
+static void
+gistAdjustKeys(Relation r, GISTSTACK * stk, BlockNumber blk,
+ char *datum, int att_size, GISTSTATE * giststate);
+static void
+gistintinsert(Relation r, GISTSTACK * stk, IndexTuple ltup,
+ IndexTuple rtup, GISTSTATE * giststate);
+static InsertIndexResult
+gistSplit(Relation r, Buffer buffer,
+ GISTSTACK * stack, IndexTuple itup,
+ GISTSTATE * giststate);
+static void
+gistnewroot(GISTSTATE * giststate, Relation r, IndexTuple lt,
IndexTuple rt);
-static void GISTInitBuffer(Buffer b, uint32 f);
-static BlockNumber gistChooseSubtree(Relation r, IndexTuple itup, int level,
- GISTSTATE *giststate,
- GISTSTACK **retstack, Buffer *leafbuf);
-static OffsetNumber gistchoose(Relation r, Page p, IndexTuple it,
- GISTSTATE *giststate);
-static int gistnospace(Page p, IndexTuple it);
-void gistdelete(Relation r, ItemPointer tid);
+static void GISTInitBuffer(Buffer b, uint32 f);
+static BlockNumber
+gistChooseSubtree(Relation r, IndexTuple itup, int level,
+ GISTSTATE * giststate,
+ GISTSTACK ** retstack, Buffer * leafbuf);
+static OffsetNumber
+gistchoose(Relation r, Page p, IndexTuple it,
+ GISTSTATE * giststate);
+static int gistnospace(Page p, IndexTuple it);
+void gistdelete(Relation r, ItemPointer tid);
static IndexTuple gist_tuple_replacekey(Relation r, GISTENTRY entry, IndexTuple t);
-static void gistcentryinit(GISTSTATE *giststate, GISTENTRY *e, char *pr,
- Relation r, Page pg, OffsetNumber o, int b, bool l) ;
-static char *int_range_out(INTRANGE *r);
+static void
+gistcentryinit(GISTSTATE * giststate, GISTENTRY * e, char *pr,
+ Relation r, Page pg, OffsetNumber o, int b, bool l);
+static char *int_range_out(INTRANGE * r);
/*
** routine to build an index. Basically calls insert over and over
*/
void
gistbuild(Relation heap,
- Relation index,
- int natts,
- AttrNumber *attnum,
- IndexStrategy istrat,
- uint16 pint,
- Datum *params,
- FuncIndexInfo *finfo,
- PredInfo *predInfo)
+ Relation index,
+ int natts,
+ AttrNumber * attnum,
+ IndexStrategy istrat,
+ uint16 pint,
+ Datum * params,