Header And Logo

PostgreSQL
| The world's most advanced open source database.

scankey.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * scankey.c
00004  *    scan key support code
00005  *
00006  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00007  * Portions Copyright (c) 1994, Regents of the University of California
00008  *
00009  *
00010  * IDENTIFICATION
00011  *    src/backend/access/common/scankey.c
00012  *
00013  *-------------------------------------------------------------------------
00014  */
00015 #include "postgres.h"
00016 
00017 #include "access/skey.h"
00018 #include "catalog/pg_collation.h"
00019 
00020 
00021 /*
00022  * ScanKeyEntryInitialize
00023  *      Initializes a scan key entry given all the field values.
00024  *      The target procedure is specified by OID (but can be invalid
00025  *      if SK_SEARCHNULL or SK_SEARCHNOTNULL is set).
00026  *
00027  * Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
00028  * itself, because that's what will be used for any subsidiary info attached
00029  * to the ScanKey's FmgrInfo record.
00030  */
00031 void
00032 ScanKeyEntryInitialize(ScanKey entry,
00033                        int flags,
00034                        AttrNumber attributeNumber,
00035                        StrategyNumber strategy,
00036                        Oid subtype,
00037                        Oid collation,
00038                        RegProcedure procedure,
00039                        Datum argument)
00040 {
00041     entry->sk_flags = flags;
00042     entry->sk_attno = attributeNumber;
00043     entry->sk_strategy = strategy;
00044     entry->sk_subtype = subtype;
00045     entry->sk_collation = collation;
00046     entry->sk_argument = argument;
00047     if (RegProcedureIsValid(procedure))
00048     {
00049         fmgr_info(procedure, &entry->sk_func);
00050     }
00051     else
00052     {
00053         Assert(flags & (SK_SEARCHNULL | SK_SEARCHNOTNULL));
00054         MemSet(&entry->sk_func, 0, sizeof(entry->sk_func));
00055     }
00056 }
00057 
00058 /*
00059  * ScanKeyInit
00060  *      Shorthand version of ScanKeyEntryInitialize: flags and subtype
00061  *      are assumed to be zero (the usual value), and collation is defaulted.
00062  *
00063  * This is the recommended version for hardwired lookups in system catalogs.
00064  * It cannot handle NULL arguments, unary operators, or nondefault operators,
00065  * but we need none of those features for most hardwired lookups.
00066  *
00067  * We set collation to DEFAULT_COLLATION_OID always.  This is appropriate
00068  * for textual columns in system catalogs, and it will be ignored for
00069  * non-textual columns, so it's not worth trying to be more finicky.
00070  *
00071  * Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
00072  * itself, because that's what will be used for any subsidiary info attached
00073  * to the ScanKey's FmgrInfo record.
00074  */
00075 void
00076 ScanKeyInit(ScanKey entry,
00077             AttrNumber attributeNumber,
00078             StrategyNumber strategy,
00079             RegProcedure procedure,
00080             Datum argument)
00081 {
00082     entry->sk_flags = 0;
00083     entry->sk_attno = attributeNumber;
00084     entry->sk_strategy = strategy;
00085     entry->sk_subtype = InvalidOid;
00086     entry->sk_collation = DEFAULT_COLLATION_OID;
00087     entry->sk_argument = argument;
00088     fmgr_info(procedure, &entry->sk_func);
00089 }
00090 
00091 /*
00092  * ScanKeyEntryInitializeWithInfo
00093  *      Initializes a scan key entry using an already-completed FmgrInfo
00094  *      function lookup record.
00095  *
00096  * Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
00097  * itself, because that's what will be used for any subsidiary info attached
00098  * to the ScanKey's FmgrInfo record.
00099  */
00100 void
00101 ScanKeyEntryInitializeWithInfo(ScanKey entry,
00102                                int flags,
00103                                AttrNumber attributeNumber,
00104                                StrategyNumber strategy,
00105                                Oid subtype,
00106                                Oid collation,
00107                                FmgrInfo *finfo,
00108                                Datum argument)
00109 {
00110     entry->sk_flags = flags;
00111     entry->sk_attno = attributeNumber;
00112     entry->sk_strategy = strategy;
00113     entry->sk_subtype = subtype;
00114     entry->sk_collation = collation;
00115     entry->sk_argument = argument;
00116     fmgr_info_copy(&entry->sk_func, finfo, CurrentMemoryContext);
00117 }