7
7
#include "tsearch/ts_locale.h"
8
8
#include "utils/memutils.h"
9
9
10
+
11
+ /* ltree */
12
+
13
+ /*
14
+ * We want the maximum length of a label to be encoding-independent, so
15
+ * set it somewhat arbitrarily at 255 characters (not bytes), while using
16
+ * uint16 fields to hold the byte length.
17
+ */
18
+ #define LTREE_LABEL_MAX_CHARS 255
19
+
10
20
typedef struct
11
21
{
12
- uint16 len ;
22
+ uint16 len ; /* label string length in bytes */
13
23
char name [FLEXIBLE_ARRAY_MEMBER ];
14
24
} ltree_level ;
15
25
@@ -19,7 +29,8 @@ typedef struct
19
29
typedef struct
20
30
{
21
31
int32 vl_len_ ; /* varlena header (do not touch directly!) */
22
- uint16 numlevel ;
32
+ uint16 numlevel ; /* number of labels */
33
+ /* Array of maxalign'd ltree_level structs follows: */
23
34
char data [FLEXIBLE_ARRAY_MEMBER ];
24
35
} ltree ;
25
36
@@ -30,25 +41,35 @@ typedef struct
30
41
31
42
/* lquery */
32
43
44
+ /* lquery_variant: one branch of some OR'ed alternatives */
33
45
typedef struct
34
46
{
35
- int32 val ;
36
- uint16 len ;
47
+ int32 val ; /* CRC of label string */
48
+ uint16 len ; /* label string length in bytes */
37
49
uint8 flag ; /* see LVAR_xxx flags below */
38
50
char name [FLEXIBLE_ARRAY_MEMBER ];
39
51
} lquery_variant ;
40
52
53
+ /*
54
+ * Note: these macros contain too many MAXALIGN calls and so will sometimes
55
+ * overestimate the space needed for an lquery_variant. However, we can't
56
+ * change it without breaking on-disk compatibility for lquery.
57
+ */
41
58
#define LVAR_HDRSIZE MAXALIGN(offsetof(lquery_variant, name))
42
59
#define LVAR_NEXT (x ) ( (lquery_variant*)( ((char*)(x)) + MAXALIGN(((lquery_variant*)(x))->len) + LVAR_HDRSIZE ) )
43
60
44
- #define LVAR_ANYEND 0x01
45
- #define LVAR_INCASE 0x02
46
- #define LVAR_SUBLEXEME 0x04
61
+ #define LVAR_ANYEND 0x01 /* '*' flag: prefix match */
62
+ #define LVAR_INCASE 0x02 /* '@' flag: case-insensitive match */
63
+ #define LVAR_SUBLEXEME 0x04 /* '%' flag: word-wise match */
47
64
65
+ /*
66
+ * In an lquery_level, "flag" contains the union of the variants' flags
67
+ * along with possible LQL_xxx flags; so those bit sets can't overlap.
68
+ */
48
69
typedef struct
49
70
{
50
71
uint16 totallen ; /* total length of this level, in bytes */
51
- uint16 flag ; /* see LQL_xxx flags below */
72
+ uint16 flag ; /* see LQL_xxx and LVAR_xxx flags */
52
73
uint16 numvar ; /* number of variants; 0 means '*' */
53
74
uint16 low ; /* minimum repeat count for '*' */
54
75
uint16 high ; /* maximum repeat count for '*' */
@@ -60,7 +81,7 @@ typedef struct
60
81
#define LQL_NEXT (x ) ( (lquery_level*)( ((char*)(x)) + MAXALIGN(((lquery_level*)(x))->totallen) ) )
61
82
#define LQL_FIRST (x ) ( (lquery_variant*)( ((char*)(x))+LQL_HDRSIZE ) )
62
83
63
- #define LQL_NOT 0x10
84
+ #define LQL_NOT 0x10 /* level has '!' (NOT) prefix */
64
85
65
86
#ifdef LOWER_NODE
66
87
#define FLG_CANLOOKSIGN (x ) ( ( (x) & ( LQL_NOT | LVAR_ANYEND | LVAR_SUBLEXEME ) ) == 0 )
@@ -73,7 +94,7 @@ typedef struct
73
94
{
74
95
int32 vl_len_ ; /* varlena header (do not touch directly!) */
75
96
uint16 numlevel ; /* number of lquery_levels */
76
- uint16 firstgood ;
97
+ uint16 firstgood ; /* number of leading simple-match levels */
77
98
uint16 flag ; /* see LQUERY_xxx flags below */
78
99
/* Array of maxalign'd lquery_level structs follows: */
79
100
char data [FLEXIBLE_ARRAY_MEMBER ];
0 commit comments