LCOV - code coverage report
Current view: top level - src/backend/access/common - scankey.c (source / functions) Hit Total Coverage
Test: PostgreSQL 11devel Lines: 29 29 100.0 %
Date: 2017-11-22 12:18:04 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 12 66.7 %

           Branch data     Line data    Source code
       1                 :            : /*-------------------------------------------------------------------------
       2                 :            :  *
       3                 :            :  * scankey.c
       4                 :            :  *    scan key support code
       5                 :            :  *
       6                 :            :  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
       7                 :            :  * Portions Copyright (c) 1994, Regents of the University of California
       8                 :            :  *
       9                 :            :  *
      10                 :            :  * IDENTIFICATION
      11                 :            :  *    src/backend/access/common/scankey.c
      12                 :            :  *
      13                 :            :  *-------------------------------------------------------------------------
      14                 :            :  */
      15                 :            : #include "postgres.h"
      16                 :            : 
      17                 :            : #include "access/skey.h"
      18                 :            : #include "catalog/pg_collation.h"
      19                 :            : 
      20                 :            : 
      21                 :            : /*
      22                 :            :  * ScanKeyEntryInitialize
      23                 :            :  *      Initializes a scan key entry given all the field values.
      24                 :            :  *      The target procedure is specified by OID (but can be invalid
      25                 :            :  *      if SK_SEARCHNULL or SK_SEARCHNOTNULL is set).
      26                 :            :  *
      27                 :            :  * Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
      28                 :            :  * itself, because that's what will be used for any subsidiary info attached
      29                 :            :  * to the ScanKey's FmgrInfo record.
      30                 :            :  */
      31                 :            : void
      32                 :    1141268 : ScanKeyEntryInitialize(ScanKey entry,
      33                 :            :                        int flags,
      34                 :            :                        AttrNumber attributeNumber,
      35                 :            :                        StrategyNumber strategy,
      36                 :            :                        Oid subtype,
      37                 :            :                        Oid collation,
      38                 :            :                        RegProcedure procedure,
      39                 :            :                        Datum argument)
      40                 :            : {
      41                 :    1141268 :     entry->sk_flags = flags;
      42                 :    1141268 :     entry->sk_attno = attributeNumber;
      43                 :    1141268 :     entry->sk_strategy = strategy;
      44                 :    1141268 :     entry->sk_subtype = subtype;
      45                 :    1141268 :     entry->sk_collation = collation;
      46                 :    1141268 :     entry->sk_argument = argument;
      47         [ +  + ]:    1141268 :     if (RegProcedureIsValid(procedure))
      48                 :            :     {
      49                 :    1128338 :         fmgr_info(procedure, &entry->sk_func);
      50                 :            :     }
      51                 :            :     else
      52                 :            :     {
      53                 :            :         Assert(flags & (SK_SEARCHNULL | SK_SEARCHNOTNULL));
      54 [ +  - ][ +  - ]:      90510 :         MemSet(&entry->sk_func, 0, sizeof(entry->sk_func));
         [ +  - ][ +  - ]
                 [ +  + ]
      55                 :            :     }
      56                 :    1141268 : }
      57                 :            : 
      58                 :            : /*
      59                 :            :  * ScanKeyInit
      60                 :            :  *      Shorthand version of ScanKeyEntryInitialize: flags and subtype
      61                 :            :  *      are assumed to be zero (the usual value), and collation is defaulted.
      62                 :            :  *
      63                 :            :  * This is the recommended version for hardwired lookups in system catalogs.
      64                 :            :  * It cannot handle NULL arguments, unary operators, or nondefault operators,
      65                 :            :  * but we need none of those features for most hardwired lookups.
      66                 :            :  *
      67                 :            :  * We set collation to DEFAULT_COLLATION_OID always.  This is appropriate
      68                 :            :  * for textual columns in system catalogs, and it will be ignored for
      69                 :            :  * non-textual columns, so it's not worth trying to be more finicky.
      70                 :            :  *
      71                 :            :  * Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
      72                 :            :  * itself, because that's what will be used for any subsidiary info attached
      73                 :            :  * to the ScanKey's FmgrInfo record.
      74                 :            :  */
      75                 :            : void
      76                 :    8499566 : ScanKeyInit(ScanKey entry,
      77                 :            :             AttrNumber attributeNumber,
      78                 :            :             StrategyNumber strategy,
      79                 :            :             RegProcedure procedure,
      80                 :            :             Datum argument)
      81                 :            : {
      82                 :    8499566 :     entry->sk_flags = 0;
      83                 :    8499566 :     entry->sk_attno = attributeNumber;
      84                 :    8499566 :     entry->sk_strategy = strategy;
      85                 :    8499566 :     entry->sk_subtype = InvalidOid;
      86                 :    8499566 :     entry->sk_collation = DEFAULT_COLLATION_OID;
      87                 :    8499566 :     entry->sk_argument = argument;
      88                 :    8499566 :     fmgr_info(procedure, &entry->sk_func);
      89                 :    8499566 : }
      90                 :            : 
      91                 :            : /*
      92                 :            :  * ScanKeyEntryInitializeWithInfo
      93                 :            :  *      Initializes a scan key entry using an already-completed FmgrInfo
      94                 :            :  *      function lookup record.
      95                 :            :  *
      96                 :            :  * Note: CurrentMemoryContext at call should be as long-lived as the ScanKey
      97                 :            :  * itself, because that's what will be used for any subsidiary info attached
      98                 :            :  * to the ScanKey's FmgrInfo record.
      99                 :            :  */
     100                 :            : void
     101                 :   37284416 : ScanKeyEntryInitializeWithInfo(ScanKey entry,
     102                 :            :                                int flags,
     103                 :            :                                AttrNumber attributeNumber,
     104                 :            :                                StrategyNumber strategy,
     105                 :            :                                Oid subtype,
     106                 :            :                                Oid collation,
     107                 :            :                                FmgrInfo *finfo,
     108                 :            :                                Datum argument)
     109                 :            : {
     110                 :   37284416 :     entry->sk_flags = flags;
     111                 :   37284416 :     entry->sk_attno = attributeNumber;
     112                 :   37284416 :     entry->sk_strategy = strategy;
     113                 :   37284416 :     entry->sk_subtype = subtype;
     114                 :   37284416 :     entry->sk_collation = collation;
     115                 :   37284416 :     entry->sk_argument = argument;
     116                 :   37284416 :     fmgr_info_copy(&entry->sk_func, finfo, CurrentMemoryContext);
     117                 :   37284416 : }

Generated by: LCOV version 1.13