You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

scankey.c 3.5KB

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