mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-10 01:02:56 +03:00
Improvements to the application-defined function mechanism so that it is
more compact and runs faster, especially when the application defines thousands of new SQL functions. FossilOrigin-Name: 3201fbcc5105d23132e6b8b7ac825e66af4f8a39
This commit is contained in:
@@ -1109,13 +1109,15 @@ struct LookasideSlot {
|
||||
};
|
||||
|
||||
/*
|
||||
** A hash table for function definitions.
|
||||
** A hash table for built-in function definitions. (Application-defined
|
||||
** functions use a regular table table from hash.h.)
|
||||
**
|
||||
** Hash each FuncDef structure into one of the FuncDefHash.a[] slots.
|
||||
** Collisions are on the FuncDef.pHash chain.
|
||||
** Collisions are on the FuncDef.u.pHash chain.
|
||||
*/
|
||||
#define SQLITE_FUNC_HASH_SZ 23
|
||||
struct FuncDefHash {
|
||||
FuncDef *a[23]; /* Hash table for functions */
|
||||
FuncDef *a[SQLITE_FUNC_HASH_SZ]; /* Hash table for functions */
|
||||
};
|
||||
|
||||
#ifdef SQLITE_USER_AUTHENTICATION
|
||||
@@ -1243,7 +1245,7 @@ struct sqlite3 {
|
||||
VTable **aVTrans; /* Virtual tables with open transactions */
|
||||
VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */
|
||||
#endif
|
||||
FuncDefHash aFunc; /* Hash table of connection functions */
|
||||
Hash aFunc; /* Hash table of connection functions */
|
||||
Hash aCollSeq; /* All collating sequences */
|
||||
BusyHandler busyHandler; /* Busy callback */
|
||||
Db aDbStatic[2]; /* Static space for the 2 default backends */
|
||||
@@ -1370,20 +1372,26 @@ struct sqlite3 {
|
||||
|
||||
/*
|
||||
** Each SQL function is defined by an instance of the following
|
||||
** structure. A pointer to this structure is stored in the sqlite.aFunc
|
||||
** hash table. When multiple functions have the same name, the hash table
|
||||
** points to a linked list of these structures.
|
||||
** structure. For global built-in functions (ex: substr(), max(), count())
|
||||
** a pointer to this structure is held in the sqlite3BuiltinFunctions object.
|
||||
** For per-connection application-defined functions, a pointer to this
|
||||
** structure is held in the db->aHash hash table.
|
||||
**
|
||||
** The u.pHash field is used by the global built-ins. The u.pDestructor
|
||||
** field is used by per-connection app-def functions.
|
||||
*/
|
||||
struct FuncDef {
|
||||
i16 nArg; /* Number of arguments. -1 means unlimited */
|
||||
i8 nArg; /* Number of arguments. -1 means unlimited */
|
||||
u16 funcFlags; /* Some combination of SQLITE_FUNC_* */
|
||||
void *pUserData; /* User data parameter */
|
||||
FuncDef *pNext; /* Next function with same name */
|
||||
void (*xSFunc)(sqlite3_context*,int,sqlite3_value**); /* func or agg-step */
|
||||
void (*xFinalize)(sqlite3_context*); /* Agg finalizer */
|
||||
char *zName; /* SQL name of the function. */
|
||||
FuncDef *pHash; /* Next with a different name but the same hash */
|
||||
FuncDestructor *pDestructor; /* Reference counted destructor function */
|
||||
union {
|
||||
FuncDef *pHash; /* Next with a different name but the same hash */
|
||||
FuncDestructor *pDestructor; /* Reference counted destructor function */
|
||||
} u;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -1463,28 +1471,28 @@ struct FuncDestructor {
|
||||
*/
|
||||
#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
|
||||
{nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
|
||||
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, 0, 0}
|
||||
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
|
||||
#define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
|
||||
{nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
|
||||
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, 0, 0}
|
||||
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
|
||||
#define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
|
||||
{nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
|
||||
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, 0, 0}
|
||||
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
|
||||
#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
|
||||
{nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
|
||||
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, 0, 0}
|
||||
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
|
||||
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
|
||||
{nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
|
||||
pArg, 0, xFunc, 0, #zName, 0, 0}
|
||||
pArg, 0, xFunc, 0, #zName, }
|
||||
#define LIKEFUNC(zName, nArg, arg, flags) \
|
||||
{nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
|
||||
(void *)arg, 0, likeFunc, 0, #zName, 0, 0}
|
||||
(void *)arg, 0, likeFunc, 0, #zName, {0} }
|
||||
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
|
||||
{nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
|
||||
SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName,0,0}
|
||||
SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName, {0}}
|
||||
#define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \
|
||||
{nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
|
||||
SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName,0,0}
|
||||
SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName, {0}}
|
||||
|
||||
/*
|
||||
** All current savepoints are stored in a linked list starting at
|
||||
@@ -3225,7 +3233,7 @@ int sqlite3IsIdChar(u8);
|
||||
/*
|
||||
** Internal function prototypes
|
||||
*/
|
||||
#define sqlite3StrICmp sqlite3_stricmp
|
||||
int sqlite3StrICmp(const char*,const char*);
|
||||
int sqlite3Strlen30(const char*);
|
||||
#define sqlite3StrNICmp sqlite3_strnicmp
|
||||
|
||||
@@ -3572,11 +3580,11 @@ void sqlite3SelectSetName(Select*,const char*);
|
||||
#else
|
||||
# define sqlite3SelectSetName(A,B)
|
||||
#endif
|
||||
void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*);
|
||||
FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,u8);
|
||||
void sqlite3RegisterBuiltinFunctions(sqlite3*);
|
||||
void sqlite3InsertBuiltinFuncs(FuncDef*,int);
|
||||
FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,u8,u8);
|
||||
void sqlite3RegisterBuiltinFunctions(void);
|
||||
void sqlite3RegisterDateTimeFunctions(void);
|
||||
void sqlite3RegisterGlobalFunctions(void);
|
||||
void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3*);
|
||||
int sqlite3SafetyCheckOk(sqlite3*);
|
||||
int sqlite3SafetyCheckSickOrOk(sqlite3*);
|
||||
void sqlite3ChangeCookie(Parse*, int);
|
||||
@@ -3737,7 +3745,7 @@ extern const unsigned char sqlite3UpperToLower[];
|
||||
extern const unsigned char sqlite3CtypeMap[];
|
||||
extern const Token sqlite3IntTokens[];
|
||||
extern SQLITE_WSD struct Sqlite3Config sqlite3Config;
|
||||
extern SQLITE_WSD FuncDefHash sqlite3GlobalFunctions;
|
||||
extern FuncDefHash sqlite3BuiltinFunctions;
|
||||
#ifndef SQLITE_OMIT_WSD
|
||||
extern int sqlite3PendingByte;
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user