| 1 |
/*------------------------------------------------------------------------- |
| 2 |
* |
| 3 |
* pgbench.h |
| 4 |
* |
| 5 |
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group |
| 6 |
* Portions Copyright (c) 1994, Regents of the University of California |
| 7 |
* |
| 8 |
*------------------------------------------------------------------------- |
| 9 |
*/ |
| 10 |
|
| 11 |
#ifndef PGBENCH_H |
| 12 |
#define PGBENCH_H |
| 13 |
|
| 14 |
#include "fe_utils/psqlscan.h" |
| 15 |
|
| 16 |
/* |
| 17 |
* This file is included outside exprscan.l, in places where we can't see |
| 18 |
* flex's definition of typedef yyscan_t. Fortunately, it's documented as |
| 19 |
* being "void *", so we can use a macro to keep the function declarations |
| 20 |
* here looking like the definitions in exprscan.l. exprparse.y and |
| 21 |
* pgbench.c also use this to be able to declare things as "yyscan_t". |
| 22 |
*/ |
| 23 |
#define yyscan_t void * |
| 24 |
|
| 25 |
/* |
| 26 |
* Likewise, we can't see exprparse.y's definition of union YYSTYPE here, |
| 27 |
* but for now there's no need to know what the union contents are. |
| 28 |
*/ |
| 29 |
union YYSTYPE; |
| 30 |
|
| 31 |
/* |
| 32 |
* Variable types used in parser. |
| 33 |
*/ |
| 34 |
typedef enum |
| 35 |
{ |
| 36 |
PGBT_NO_VALUE = 0, |
| 37 |
PGBT_NULL, |
| 38 |
PGBT_INT, |
| 39 |
PGBT_DOUBLE, |
| 40 |
PGBT_BOOLEAN, |
| 41 |
/* add other types here */ |
| 42 |
} PgBenchValueType; |
| 43 |
|
| 44 |
typedef struct |
| 45 |
{ |
| 46 |
PgBenchValueType type; |
| 47 |
union |
| 48 |
{ |
| 49 |
int64 ival; |
| 50 |
double dval; |
| 51 |
bool bval; |
| 52 |
/* add other types here */ |
| 53 |
} u; |
| 54 |
} PgBenchValue; |
| 55 |
|
| 56 |
/* Types of expression nodes */ |
| 57 |
typedef enum PgBenchExprType |
| 58 |
{ |
| 59 |
ENODE_CONSTANT, |
| 60 |
ENODE_VARIABLE, |
| 61 |
ENODE_FUNCTION, |
| 62 |
} PgBenchExprType; |
| 63 |
|
| 64 |
/* List of operators and callable functions */ |
| 65 |
typedef enum PgBenchFunction |
| 66 |
{ |
| 67 |
PGBENCH_ADD, |
| 68 |
PGBENCH_SUB, |
| 69 |
PGBENCH_MUL, |
| 70 |
PGBENCH_DIV, |
| 71 |
PGBENCH_MOD, |
| 72 |
PGBENCH_DEBUG, |
| 73 |
PGBENCH_ABS, |
| 74 |
PGBENCH_LEAST, |
| 75 |
PGBENCH_GREATEST, |
| 76 |
PGBENCH_INT, |
| 77 |
PGBENCH_DOUBLE, |
| 78 |
PGBENCH_PI, |
| 79 |
PGBENCH_SQRT, |
| 80 |
PGBENCH_LN, |
| 81 |
PGBENCH_EXP, |
| 82 |
PGBENCH_RANDOM, |
| 83 |
PGBENCH_RANDOM_GAUSSIAN, |
| 84 |
PGBENCH_RANDOM_EXPONENTIAL, |
| 85 |
PGBENCH_RANDOM_ZIPFIAN, |
| 86 |
PGBENCH_POW, |
| 87 |
PGBENCH_AND, |
| 88 |
PGBENCH_OR, |
| 89 |
PGBENCH_NOT, |
| 90 |
PGBENCH_BITAND, |
| 91 |
PGBENCH_BITOR, |
| 92 |
PGBENCH_BITXOR, |
| 93 |
PGBENCH_LSHIFT, |
| 94 |
PGBENCH_RSHIFT, |
| 95 |
PGBENCH_EQ, |
| 96 |
PGBENCH_NE, |
| 97 |
PGBENCH_LE, |
| 98 |
PGBENCH_LT, |
| 99 |
PGBENCH_IS, |
| 100 |
PGBENCH_CASE, |
| 101 |
PGBENCH_HASH_FNV1A, |
| 102 |
PGBENCH_HASH_MURMUR2, |
| 103 |
PGBENCH_PERMUTE, |
| 104 |
} PgBenchFunction; |
| 105 |
|
| 106 |
typedef struct PgBenchExpr PgBenchExpr; |
| 107 |
typedef struct PgBenchExprLink PgBenchExprLink; |
| 108 |
typedef struct PgBenchExprList PgBenchExprList; |
| 109 |
|
| 110 |
struct PgBenchExpr |
| 111 |
{ |
| 112 |
PgBenchExprType etype; |
| 113 |
union |
| 114 |
{ |
| 115 |
PgBenchValue constant; |
| 116 |
struct |
| 117 |
{ |
| 118 |
char *varname; |
| 119 |
} variable; |
| 120 |
struct |
| 121 |
{ |
| 122 |
PgBenchFunction function; |
| 123 |
PgBenchExprLink *args; |
| 124 |
} function; |
| 125 |
} u; |
| 126 |
}; |
| 127 |
|
| 128 |
/* List of expression nodes */ |
| 129 |
struct PgBenchExprLink |
| 130 |
{ |
| 131 |
PgBenchExpr *expr; |
| 132 |
PgBenchExprLink *next; |
| 133 |
}; |
| 134 |
|
| 135 |
struct PgBenchExprList |
| 136 |
{ |
| 137 |
PgBenchExprLink *head; |
| 138 |
PgBenchExprLink *tail; |
| 139 |
}; |
| 140 |
|
| 141 |
extern int expr_yyparse(PgBenchExpr **expr_parse_result_p, yyscan_t yyscanner); |
| 142 |
extern int expr_yylex(union YYSTYPE *yylval_param, yyscan_t yyscanner); |
| 143 |
pg_noreturn extern void expr_yyerror(PgBenchExpr **expr_parse_result_p, yyscan_t yyscanner, const char *message); |
| 144 |
pg_noreturn extern void expr_yyerror_more(yyscan_t yyscanner, const char *message, |
| 145 |
const char *more); |
| 146 |
extern bool expr_lex_one_word(PsqlScanState state, PQExpBuffer word_buf, |
| 147 |
int *offset); |
| 148 |
extern yyscan_t expr_scanner_init(PsqlScanState state, |
| 149 |
const char *source, int lineno, int start_offset, |
| 150 |
const char *command); |
| 151 |
extern void expr_scanner_finish(yyscan_t yyscanner); |
| 152 |
extern char *expr_scanner_get_substring(PsqlScanState state, |
| 153 |
int start_offset, |
| 154 |
bool chomp); |
| 155 |
|
| 156 |
pg_noreturn extern void syntax_error(const char *source, int lineno, const char *line, |
| 157 |
const char *command, const char *msg, |
| 158 |
const char *more, int column); |
| 159 |
|
| 160 |
extern bool strtoint64(const char *str, bool errorOK, int64 *result); |
| 161 |
extern bool strtodouble(const char *str, bool errorOK, double *dv); |
| 162 |
|
| 163 |
#endif /* PGBENCH_H */ |