PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "regex/regexport.h"
#include "trgm.h"
#include "tsearch/ts_locale.h"
#include "utils/hsearch.h"
#include "utils/memutils.h"
#include "varatt.h"
Go to the source code of this file.
Data Structures | |
struct | trgm_mb_char |
struct | TrgmColorInfo |
struct | TrgmPrefix |
struct | ColorTrgm |
struct | TrgmStateKey |
struct | TrgmState |
struct | TrgmArc |
struct | TrgmArcInfo |
struct | ColorTrgmInfo |
struct | TrgmNFA |
struct | TrgmPackedArc |
struct | TrgmPackedState |
struct | TrgmPackedGraph |
struct | TrgmPackArcInfo |
Macros | |
#define | MAX_EXPANDED_STATES 128 |
#define | MAX_EXPANDED_ARCS 1024 |
#define | MAX_TRGM_COUNT 256 |
#define | WISH_TRGM_PENALTY 16 |
#define | COLOR_COUNT_LIMIT 256 |
#define | COLOR_UNKNOWN (-3) |
#define | COLOR_BLANK (-4) |
#define | TSTATE_INIT 0x01 /* flag indicating this state is initial */ |
#define | TSTATE_FIN 0x02 /* flag indicating this state is final */ |
Typedefs | |
typedef int | TrgmColor |
typedef struct TrgmState | TrgmState |
Functions | |
static TRGM * | createTrgmNFAInternal (regex_t *regex, TrgmPackedGraph **graph, MemoryContext rcontext) |
static void | RE_compile (regex_t *regex, text *text_re, int cflags, Oid collation) |
static void | getColorInfo (regex_t *regex, TrgmNFA *trgmNFA) |
static bool | convertPgWchar (pg_wchar c, trgm_mb_char *result) |
static void | transformGraph (TrgmNFA *trgmNFA) |
static void | processState (TrgmNFA *trgmNFA, TrgmState *state) |
static void | addKey (TrgmNFA *trgmNFA, TrgmState *state, TrgmStateKey *key) |
static void | addKeyToQueue (TrgmNFA *trgmNFA, TrgmStateKey *key) |
static void | addArcs (TrgmNFA *trgmNFA, TrgmState *state) |
static void | addArc (TrgmNFA *trgmNFA, TrgmState *state, TrgmStateKey *key, TrgmColor co, TrgmStateKey *destKey) |
static bool | validArcLabel (TrgmStateKey *key, TrgmColor co) |
static TrgmState * | getState (TrgmNFA *trgmNFA, TrgmStateKey *key) |
static bool | prefixContains (TrgmPrefix *prefix1, TrgmPrefix *prefix2) |
static bool | selectColorTrigrams (TrgmNFA *trgmNFA) |
static TRGM * | expandColorTrigrams (TrgmNFA *trgmNFA, MemoryContext rcontext) |
static void | fillTrgm (trgm *ptrgm, trgm_mb_char s[3]) |
static void | mergeStates (TrgmState *state1, TrgmState *state2) |
static int | colorTrgmInfoCmp (const void *p1, const void *p2) |
static int | colorTrgmInfoPenaltyCmp (const void *p1, const void *p2) |
static TrgmPackedGraph * | packGraph (TrgmNFA *trgmNFA, MemoryContext rcontext) |
static int | packArcInfoCmp (const void *a1, const void *a2) |
TRGM * | createTrgmNFA (text *text_re, Oid collation, TrgmPackedGraph **graph, MemoryContext rcontext) |
bool | trigramsMatchGraph (TrgmPackedGraph *graph, bool *check) |
Variables | |
static const float4 | penalties [8] |
#define COLOR_BLANK (-4) |
Definition at line 287 of file trgm_regexp.c.
#define COLOR_COUNT_LIMIT 256 |
Definition at line 223 of file trgm_regexp.c.
#define COLOR_UNKNOWN (-3) |
Definition at line 286 of file trgm_regexp.c.
#define MAX_EXPANDED_ARCS 1024 |
Definition at line 220 of file trgm_regexp.c.
#define MAX_EXPANDED_STATES 128 |
Definition at line 219 of file trgm_regexp.c.
#define MAX_TRGM_COUNT 256 |
Definition at line 221 of file trgm_regexp.c.
Definition at line 330 of file trgm_regexp.c.
Definition at line 329 of file trgm_regexp.c.
#define WISH_TRGM_PENALTY 16 |
Definition at line 222 of file trgm_regexp.c.
typedef int TrgmColor |
Definition at line 283 of file trgm_regexp.c.
|
static |
Definition at line 1286 of file trgm_regexp.c.
References TrgmNFA::arcsCount, getState(), sort-test::key, lappend(), lfirst, TrgmStateKey::nstate, palloc(), TrgmStateKey::prefix, prefixContains(), and validArcLabel().
Referenced by addArcs().
Definition at line 1188 of file trgm_regexp.c.
References addArc(), Assert, arc::co, COLOR_BLANK, TrgmNFA::colorInfo, TrgmPrefix::colors, TrgmColorInfo::containsNonWord, TrgmColorInfo::expandable, i, sort-test::key, lfirst, MemSet, TrgmNFA::ncolors, TrgmStateKey::nstate, palloc(), pfree(), pg_reg_getnumoutarcs(), pg_reg_getoutarcs(), TrgmStateKey::prefix, TrgmNFA::regex, arc::to, and TrgmColorInfo::wordCharsCount.
Referenced by processState().
|
static |
Definition at line 1007 of file trgm_regexp.c.
References addKeyToQueue(), arc::co, COLOR_BLANK, COLOR_UNKNOWN, TrgmNFA::colorInfo, TrgmPrefix::colors, TrgmColorInfo::containsNonWord, TrgmColorInfo::expandable, foreach_delete_current, i, sort-test::key, lappend(), lfirst, MemSet, TrgmStateKey::nstate, palloc(), pfree(), pg_reg_colorisbegin(), pg_reg_colorisend(), pg_reg_getfinalstate(), pg_reg_getnumoutarcs(), pg_reg_getoutarcs(), TrgmStateKey::prefix, prefixContains(), TrgmNFA::regex, arc::to, TSTATE_FIN, validArcLabel(), and TrgmColorInfo::wordCharsCount.
Referenced by processState().
|
static |
Definition at line 1176 of file trgm_regexp.c.
References sort-test::key, TrgmNFA::keysQueue, lappend(), and palloc().
Referenced by addKey().
|
static |
Definition at line 1892 of file trgm_regexp.c.
References ColorTrgmInfo::ctrgm, and p2.
Referenced by packGraph(), and selectColorTrigrams().
|
static |
|
static |
Definition at line 827 of file trgm_regexp.c.
References trgm_mb_char::bytes, lowerstr(), MAX_MULTIBYTE_CHAR_LEN, pfree(), and pg_wchar2mb_with_len().
Referenced by getColorInfo().
TRGM* createTrgmNFA | ( | text * | text_re, |
Oid | collation, | ||
TrgmPackedGraph ** | graph, | ||
MemoryContext | rcontext | ||
) |
Definition at line 522 of file trgm_regexp.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, createTrgmNFAInternal(), CurrentMemoryContext, MemoryContextDelete(), MemoryContextSwitchTo(), RE_compile(), REG_ADVANCED, REG_ICASE, REG_NOSUB, and regex_t.
Referenced by gin_extract_query_trgm(), and gtrgm_consistent().
|
static |
Definition at line 565 of file trgm_regexp.c.
References TrgmNFA::colorInfo, expandColorTrigrams(), TrgmState::flags, getColorInfo(), TrgmNFA::initState, TrgmNFA::ncolors, packGraph(), TrgmNFA::regex, selectColorTrigrams(), transformGraph(), and TSTATE_FIN.
Referenced by createTrgmNFA().
|
static |
Definition at line 1775 of file trgm_regexp.c.
References ARRKEY, trgm_mb_char::bytes, CALCGTSIZE, COLOR_BLANK, TrgmNFA::colorInfo, ColorTrgm::colors, TrgmNFA::colorTrgms, TrgmNFA::colorTrgmsCount, ColorTrgmInfo::ctrgm, ColorTrgmInfo::expanded, fillTrgm(), TRGM::flag, GETARR, i, j, MemoryContextAllocZero(), SET_VARSIZE, TrgmNFA::totalTrgmCount, TRGMHDRSIZE, TrgmColorInfo::wordChars, and TrgmColorInfo::wordCharsCount.
Referenced by createTrgmNFAInternal().
|
static |
Definition at line 1843 of file trgm_regexp.c.
References trgm_mb_char::bytes, compact_trigram(), i, j, MAX_MULTIBYTE_CHAR_LEN, and str.
Referenced by expandColorTrigrams().
Definition at line 763 of file trgm_regexp.c.
References chars, COLOR_COUNT_LIMIT, TrgmNFA::colorInfo, TrgmColorInfo::containsNonWord, convertPgWchar(), TrgmColorInfo::expandable, i, ISWORDCHR, j, TrgmNFA::ncolors, palloc(), palloc0(), pfree(), pg_reg_getcharacters(), pg_reg_getnumcharacters(), pg_reg_getnumcolors(), TrgmColorInfo::wordChars, and TrgmColorInfo::wordCharsCount.
Referenced by createTrgmNFAInternal().
|
static |
Definition at line 1383 of file trgm_regexp.c.
References HASH_ENTER, hash_search(), sort-test::key, lappend(), NIL, TrgmNFA::nstates, TrgmNFA::queue, and TrgmNFA::states.
Referenced by addArc(), and transformGraph().
Definition at line 1875 of file trgm_regexp.c.
References Assert, TrgmState::flags, and TrgmState::parent.
Referenced by selectColorTrigrams().
|
static |
Definition at line 2091 of file trgm_regexp.c.
References a1, a2, TrgmPackArcInfo::colorTrgm, p2, TrgmPackArcInfo::sourceState, and TrgmPackArcInfo::targetState.
Referenced by packGraph().
|
static |
Definition at line 1930 of file trgm_regexp.c.
References TrgmPackedState::arcs, TrgmNFA::arcsCount, TrgmPackedState::arcsCount, Assert, ColorTrgmInfo::cnumber, TrgmPackedArc::colorTrgm, TrgmPackArcInfo::colorTrgm, colorTrgmInfoCmp(), TrgmNFA::colorTrgms, TrgmNFA::colorTrgmsCount, TrgmPackedGraph::colorTrigramGroups, TrgmPackedGraph::colorTrigramsActive, TrgmPackedGraph::colorTrigramsCount, ColorTrgmInfo::count, ColorTrgmInfo::expanded, hash_seq_init(), hash_seq_search(), i, j, lfirst, MemoryContextAlloc(), p2, packArcInfoCmp(), palloc(), TrgmState::parent, qsort, TrgmState::snumber, source, TrgmPackArcInfo::sourceState, TrgmNFA::states, TrgmPackedGraph::states, TrgmPackedGraph::statesActive, TrgmPackedGraph::statesCount, TrgmPackedGraph::statesQueue, TrgmPackedArc::targetState, TrgmPackArcInfo::targetState, TSTATE_FIN, and TSTATE_INIT.
Referenced by createTrgmNFAInternal().
|
static |
Definition at line 957 of file trgm_regexp.c.
References addArcs(), addKey(), sort-test::key, TrgmNFA::keysQueue, lfirst, list_free(), NIL, and TSTATE_FIN.
Referenced by transformGraph().
Definition at line 719 of file trgm_regexp.c.
References ereport, errcode(), errmsg(), ERROR, palloc(), pfree(), pg_mb2wchar_with_len(), pg_regcomp(), pg_regerror(), REG_OKAY, VARDATA_ANY, and VARSIZE_ANY_EXHDR.
Referenced by createTrgmNFA().
Definition at line 1456 of file trgm_regexp.c.
References ColorTrgmInfo::arcs, TrgmNFA::arcsCount, Assert, ColorTrgmInfo::cnumber, COLOR_BLANK, TrgmNFA::colorInfo, ColorTrgm::colors, colorTrgmInfoCmp(), colorTrgmInfoPenaltyCmp(), TrgmNFA::colorTrgms, TrgmNFA::colorTrgmsCount, ColorTrgmInfo::count, ColorTrgmInfo::ctrgm, ColorTrgmInfo::expanded, fprintf, hash_seq_init(), hash_seq_search(), i, j, lfirst, list_concat(), list_length(), list_make1, MAX_TRGM_COUNT, mergeStates(), p2, palloc(), palloc0(), penalties, ColorTrgmInfo::penalty, qsort, TrgmArcInfo::source, source, TrgmNFA::states, TrgmArcInfo::target, TrgmState::tentParent, TrgmNFA::totalTrgmCount, TSTATE_FIN, TSTATE_INIT, WISH_TRGM_PENALTY, and TrgmColorInfo::wordCharsCount.
Referenced by createTrgmNFAInternal().
|
static |
Definition at line 893 of file trgm_regexp.c.
References TrgmNFA::arcsCount, COLOR_UNKNOWN, TrgmPrefix::colors, CurrentMemoryContext, HASHCTL::entrysize, TrgmState::flags, getState(), HASH_BLOBS, HASH_CONTEXT, hash_create(), HASH_ELEM, hash_get_num_entries(), HASHCTL::hcxt, TrgmNFA::initState, HASHCTL::keysize, TrgmNFA::keysQueue, lfirst, MAX_EXPANDED_ARCS, MAX_EXPANDED_STATES, MemSet, NIL, TrgmStateKey::nstate, TrgmNFA::nstates, TrgmNFA::overflowed, pg_reg_getinitialstate(), TrgmStateKey::prefix, processState(), TrgmNFA::queue, TrgmNFA::regex, TrgmNFA::states, TSTATE_FIN, and TSTATE_INIT.
Referenced by createTrgmNFAInternal().
bool trigramsMatchGraph | ( | TrgmPackedGraph * | graph, |
bool * | check | ||
) |
Definition at line 626 of file trgm_regexp.c.
References TrgmPackedGraph::colorTrigramGroups, TrgmPackedGraph::colorTrigramsActive, TrgmPackedGraph::colorTrigramsCount, i, j, TrgmPackedGraph::states, TrgmPackedGraph::statesActive, TrgmPackedGraph::statesCount, and TrgmPackedGraph::statesQueue.
Referenced by gin_trgm_consistent(), gin_trgm_triconsistent(), and gtrgm_consistent().
|
static |
Definition at line 1328 of file trgm_regexp.c.
References Assert, COLOR_BLANK, COLOR_UNKNOWN, and sort-test::key.
|
static |
Definition at line 229 of file trgm_regexp.c.
Referenced by selectColorTrigrams().