PostgreSQL Source Code git master
Data Structures | Typedefs | Enumerations | Functions
pgbench.h File Reference
#include "fe_utils/psqlscan.h"
Include dependency graph for pgbench.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct   PgBenchValue
 
struct   PgBenchExpr
 
struct   PgBenchExprLink
 
struct   PgBenchExprList
 

Typedefs

typedef void *  yyscan_t
 
 
 
typedef struct PgBenchExpr  PgBenchExpr
 
typedef struct PgBenchExprLink  PgBenchExprLink
 
typedef struct PgBenchExprList  PgBenchExprList
 

Enumerations

 
 
 

Functions

int  expr_yyparse (PgBenchExpr **expr_parse_result_p, yyscan_t yyscanner)
 
int  expr_yylex (union YYSTYPE *yylval_param, yyscan_t yyscanner)
 
pg_noreturn void  expr_yyerror (PgBenchExpr **expr_parse_result_p, yyscan_t yyscanner, const char *message)
 
pg_noreturn void  expr_yyerror_more (yyscan_t yyscanner, const char *message, const char *more)
 
bool  expr_lex_one_word (PsqlScanState state, PQExpBuffer word_buf, int *offset)
 
yyscan_t  expr_scanner_init (PsqlScanState state, const char *source, int lineno, int start_offset, const char *command)
 
void  expr_scanner_finish (yyscan_t yyscanner)
 
char *  expr_scanner_get_substring (PsqlScanState state, int start_offset, bool chomp)
 
pg_noreturn void  syntax_error (const char *source, int lineno, const char *line, const char *command, const char *msg, const char *more, int column)
 
bool  strtoint64 (const char *str, bool errorOK, int64 *result)
 
bool  strtodouble (const char *str, bool errorOK, double *dv)
 

Typedef Documentation

PgBenchExpr

typedef struct PgBenchExpr PgBenchExpr

Definition at line 106 of file pgbench.h.

PgBenchExprLink

Definition at line 107 of file pgbench.h.

PgBenchExprList

Definition at line 108 of file pgbench.h.

PgBenchExprType

PgBenchFunction

yyscan_t

typedef void* yyscan_t

Definition at line 23 of file pgbench.h.

Enumeration Type Documentation

PgBenchExprType

Enumerator
ENODE_CONSTANT 
ENODE_VARIABLE 
ENODE_FUNCTION 

Definition at line 57 of file pgbench.h.

58{
PgBenchExprType
Definition: pgbench.h:58
@ ENODE_VARIABLE
Definition: pgbench.h:60
@ ENODE_CONSTANT
Definition: pgbench.h:59
@ ENODE_FUNCTION
Definition: pgbench.h:61

PgBenchFunction

Enumerator
PGBENCH_ADD 
PGBENCH_SUB 
PGBENCH_MUL 
PGBENCH_DIV 
PGBENCH_MOD 
PGBENCH_DEBUG 
PGBENCH_ABS 
PGBENCH_LEAST 
PGBENCH_GREATEST 
PGBENCH_INT 
PGBENCH_DOUBLE 
PGBENCH_PI 
PGBENCH_SQRT 
PGBENCH_LN 
PGBENCH_EXP 
PGBENCH_RANDOM 
PGBENCH_RANDOM_GAUSSIAN 
PGBENCH_RANDOM_EXPONENTIAL 
PGBENCH_RANDOM_ZIPFIAN 
PGBENCH_POW 
PGBENCH_AND 
PGBENCH_OR 
PGBENCH_NOT 
PGBENCH_BITAND 
PGBENCH_BITOR 
PGBENCH_BITXOR 
PGBENCH_LSHIFT 
PGBENCH_RSHIFT 
PGBENCH_EQ 
PGBENCH_NE 
PGBENCH_LE 
PGBENCH_LT 
PGBENCH_IS 
PGBENCH_CASE 
PGBENCH_HASH_FNV1A 
PGBENCH_HASH_MURMUR2 
PGBENCH_PERMUTE 

Definition at line 65 of file pgbench.h.

66{
PgBenchFunction
Definition: pgbench.h:66
@ PGBENCH_DIV
Definition: pgbench.h:70
@ PGBENCH_AND
Definition: pgbench.h:87
@ PGBENCH_DOUBLE
Definition: pgbench.h:77
@ PGBENCH_LT
Definition: pgbench.h:98
@ PGBENCH_LN
Definition: pgbench.h:80
@ PGBENCH_RANDOM_EXPONENTIAL
Definition: pgbench.h:84
@ PGBENCH_RSHIFT
Definition: pgbench.h:94
@ PGBENCH_DEBUG
Definition: pgbench.h:72
@ PGBENCH_MOD
Definition: pgbench.h:71
@ PGBENCH_GREATEST
Definition: pgbench.h:75
@ PGBENCH_BITXOR
Definition: pgbench.h:92
@ PGBENCH_RANDOM_ZIPFIAN
Definition: pgbench.h:85
@ PGBENCH_INT
Definition: pgbench.h:76
@ PGBENCH_NE
Definition: pgbench.h:96
@ PGBENCH_OR
Definition: pgbench.h:88
@ PGBENCH_LE
Definition: pgbench.h:97
@ PGBENCH_EXP
Definition: pgbench.h:81
@ PGBENCH_PI
Definition: pgbench.h:78
@ PGBENCH_ADD
Definition: pgbench.h:67
@ PGBENCH_EQ
Definition: pgbench.h:95
@ PGBENCH_LSHIFT
Definition: pgbench.h:93
@ PGBENCH_RANDOM
Definition: pgbench.h:82
@ PGBENCH_POW
Definition: pgbench.h:86
@ PGBENCH_IS
Definition: pgbench.h:99
@ PGBENCH_SUB
Definition: pgbench.h:68
@ PGBENCH_HASH_MURMUR2
Definition: pgbench.h:102
@ PGBENCH_ABS
Definition: pgbench.h:73
@ PGBENCH_BITOR
Definition: pgbench.h:91
@ PGBENCH_SQRT
Definition: pgbench.h:79
@ PGBENCH_LEAST
Definition: pgbench.h:74
@ PGBENCH_PERMUTE
Definition: pgbench.h:103
@ PGBENCH_HASH_FNV1A
Definition: pgbench.h:101
@ PGBENCH_NOT
Definition: pgbench.h:89
@ PGBENCH_BITAND
Definition: pgbench.h:90
@ PGBENCH_RANDOM_GAUSSIAN
Definition: pgbench.h:83
@ PGBENCH_MUL
Definition: pgbench.h:69
@ PGBENCH_CASE
Definition: pgbench.h:100

PgBenchValueType

Enumerator
PGBT_NO_VALUE 
PGBT_NULL 
PGBT_INT 
PGBT_DOUBLE 
PGBT_BOOLEAN 

Definition at line 34 of file pgbench.h.

35{
36 PGBT_NO_VALUE = 0,
41 /* add other types here */
PgBenchValueType
Definition: pgbench.h:35
@ PGBT_NO_VALUE
Definition: pgbench.h:36
@ PGBT_INT
Definition: pgbench.h:38
@ PGBT_NULL
Definition: pgbench.h:37
@ PGBT_DOUBLE
Definition: pgbench.h:39
@ PGBT_BOOLEAN
Definition: pgbench.h:40

Function Documentation

expr_lex_one_word()

bool expr_lex_one_word ( PsqlScanState  state,
PQExpBuffer  word_buf,
int *  offset 
)

Definition at line 318 of file exprscan.l.

319{
320 int lexresult;
321 YYSTYPE lval;
322
323 /* Must be scanning already */
324 Assert(state->scanbufhandle != NULL);
325
326 /* Set current output target */
327 state->output_buf = word_buf;
328 resetPQExpBuffer(word_buf);
329
330 /* Set input source */
331 if (state->buffer_stack != NULL)
332 yy_switch_to_buffer(state->buffer_stack->buf, state->scanner);
333 else
334 yy_switch_to_buffer(state->scanbufhandle, state->scanner);
335
336 /* Set start state */
337 state->start_state = INITIAL;
338
339 /* And lex. */
340 lexresult = yylex(&lval, state->scanner);
341
342 /* Save start offset of word, if any. */
343 if (lexresult)
344 {
345 int lineno;
346 int end_offset;
347
348 psql_scan_get_location(state, &lineno, &end_offset);
349 *offset = end_offset - word_buf->len;
350 }
351 else
352 *offset = -1;
353
354 /*
355 * In case the caller returns to using the regular SQL lexer, reselect the
356 * appropriate initial state.
357 */
359
360 return (bool) lexresult;
361}
int yylex(YYSTYPE *yylval_param, yyscan_t yyscanner)
Definition: exprscan.l:94
Assert(PointerIsAligned(start, uint64))
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:146
void psql_scan_get_location(PsqlScanState state, int *lineno, int *offset)
Definition: psqlscan.l:1335
void psql_scan_reselect_sql_lexer(PsqlScanState state)
Definition: psqlscan.l:1303
int YYSTYPE
Definition: psqlscanslash.l:39
size_t len
Definition: pqexpbuffer.h:47
Definition: regguts.h:323

References Assert(), PQExpBufferData::len, psql_scan_get_location(), psql_scan_reselect_sql_lexer(), resetPQExpBuffer(), and yylex().

Referenced by process_backslash_command().

expr_scanner_finish()

void expr_scanner_finish ( yyscan_t  yyscanner )

Definition at line 402 of file exprscan.l.

403{
404 PsqlScanState state = yyget_extra(yyscanner);
405
406 /*
407 * Reselect appropriate initial state for SQL lexer.
408 */
410}

References psql_scan_reselect_sql_lexer().

Referenced by process_backslash_command().

expr_scanner_get_substring()

char * expr_scanner_get_substring ( PsqlScanState  state,
int  start_offset,
bool  chomp 
)

Definition at line 425 of file exprscan.l.

428{
429 char *result;
430 const char *scanptr = state->scanbuf + start_offset;
431 size_t slen = strlen(scanptr);
432
433 if (chomp)
434 {
435 while (slen > 0 &&
436 (scanptr[slen - 1] == '\n' || scanptr[slen - 1] == '\r'))
437 slen--;
438 }
439
440 result = (char *) pg_malloc(slen + 1);
441 memcpy(result, scanptr, slen);
442 result[slen] = '0円';
443
444 return result;
445}
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47

References pg_malloc().

Referenced by expr_yyerror_more(), and process_backslash_command().

expr_scanner_init()

yyscan_t expr_scanner_init ( PsqlScanState  state,
const char *  source,
int  lineno,
int  start_offset,
const char *  command 
)

Definition at line 370 of file exprscan.l.

373{
374 /* Save error context info */
376 expr_lineno = lineno;
377 expr_start_offset = start_offset;
378 expr_command = command;
379
380 /* Must be scanning already */
381 Assert(state->scanbufhandle != NULL);
382
383 /* Set current output target */
384 state->output_buf = NULL;
385
386 /* Set input source */
387 if (state->buffer_stack != NULL)
388 yy_switch_to_buffer(state->buffer_stack->buf, state->scanner);
389 else
390 yy_switch_to_buffer(state->scanbufhandle, state->scanner);
391
392 /* Set start state */
393 state->start_state = EXPR;
394
395 return state->scanner;
396}
static int expr_lineno
Definition: exprscan.l:40
static const char * expr_source
Definition: exprscan.l:39
static int expr_start_offset
Definition: exprscan.l:41
static const char * expr_command
Definition: exprscan.l:42
static rewind_source * source
Definition: pg_rewind.c:89

References Assert(), expr_command, expr_lineno, expr_source, expr_start_offset, and source.

Referenced by process_backslash_command().

expr_yyerror()

pg_noreturn void expr_yyerror ( PgBenchExpr **  expr_parse_result_p,
yyscan_t  yyscanner,
const char *  message 
)

Definition at line 307 of file exprscan.l.

308{
309 expr_yyerror_more(yyscanner, message, NULL);
310}
void expr_yyerror_more(yyscan_t yyscanner, const char *message, const char *more)
Definition: exprscan.l:271

References expr_yyerror_more().

expr_yyerror_more()

pg_noreturn void expr_yyerror_more ( yyscan_t  yyscanner,
const char *  message,
const char *  more 
)

Definition at line 271 of file exprscan.l.

272{
273 PsqlScanState state = yyget_extra(yyscanner);
274 int lineno;
275 int error_detection_offset;
276 YYSTYPE lval;
277 char *full_line;
278
279 psql_scan_get_location(state, &lineno, &error_detection_offset);
280 error_detection_offset--;
281
282 /*
283 * While parsing an expression, we may not have collected the whole line
284 * yet from the input source. Lex till EOL so we can report whole line.
285 * (If we're at EOF, it's okay to call yylex() an extra time.)
286 */
287 if (!last_was_newline)
288 {
289 while (yylex(&lval, yyscanner))
290 /* skip */ ;
291 }
292
293 /* Extract the line, trimming trailing newline if any */
296 true);
297
299 message, more, error_detection_offset - expr_start_offset);
300}
static bool last_was_newline
Definition: exprscan.l:45
char * expr_scanner_get_substring(PsqlScanState state, int start_offset, bool chomp)
Definition: exprscan.l:425
void syntax_error(const char *source, int lineno, const char *line, const char *command, const char *msg, const char *more, int column)
Definition: pgbench.c:5551

References expr_command, expr_lineno, expr_scanner_get_substring(), expr_source, expr_start_offset, last_was_newline, psql_scan_get_location(), syntax_error(), and yylex().

Referenced by expr_yyerror().

expr_yylex()

int expr_yylex ( union YYSTYPEyylval_param,
yyscan_t  yyscanner 
)

expr_yyparse()

int expr_yyparse ( PgBenchExpr **  expr_parse_result_p,
yyscan_t  yyscanner 
)

Referenced by process_backslash_command().

strtodouble()

bool strtodouble ( const char *  str,
bool  errorOK,
double *  dv 
)

Definition at line 1085 of file pgbench.c.

1087{
1088 char *end;
1089
1090 errno = 0;
1091 *dv = strtod(str, &end);
1092
1093 if (unlikely(errno != 0))
1094 {
1095 if (!errorOK)
1096 pg_log_error("value \"%s\" is out of range for type double", str);
1097 return false;
1098 }
1099
1100 if (unlikely(end == str || *end != '0円'))
1101 {
1102 if (!errorOK)
1103 pg_log_error("invalid input syntax for type double: \"%s\"", str);
1104 return false;
1105 }
1106 return true;
#define unlikely(x)
Definition: c.h:402
const char * str
#define pg_log_error(...)
Definition: logging.h:106

References pg_log_error, str, and unlikely.

Referenced by makeVariableValue().

strtoint64()

bool strtoint64 ( const char *  str,
bool  errorOK,
int64result 
)

Definition at line 1014 of file pgbench.c.

1016{
1017 const char *ptr = str;
1018 int64 tmp = 0;
1019 bool neg = false;
1020
1021 /*
1022 * Do our own scan, rather than relying on sscanf which might be broken
1023 * for long long.
1024 *
1025 * As INT64_MIN can't be stored as a positive 64 bit integer, accumulate
1026 * value as a negative number.
1027 */
1028
1029 /* skip leading spaces */
1030 while (*ptr && isspace((unsigned char) *ptr))
1031 ptr++;
1032
1033 /* handle sign */
1034 if (*ptr == '-')
1035 {
1036 ptr++;
1037 neg = true;
1038 }
1039 else if (*ptr == '+')
1040 ptr++;
1041
1042 /* require at least one digit */
1043 if (unlikely(!isdigit((unsigned char) *ptr)))
1044 goto invalid_syntax;
1045
1046 /* process digits */
1047 while (*ptr && isdigit((unsigned char) *ptr))
1048 {
1049 int8 digit = (*ptr++ - '0');
1050
1051 if (unlikely(pg_mul_s64_overflow(tmp, 10, &tmp)) ||
1052 unlikely(pg_sub_s64_overflow(tmp, digit, &tmp)))
1053 goto out_of_range;
1054 }
1055
1056 /* allow trailing whitespace, but not other trailing chars */
1057 while (*ptr != '0円' && isspace((unsigned char) *ptr))
1058 ptr++;
1059
1060 if (unlikely(*ptr != '0円'))
1061 goto invalid_syntax;
1062
1063 if (!neg)
1064 {
1065 if (unlikely(tmp == PG_INT64_MIN))
1066 goto out_of_range;
1067 tmp = -tmp;
1068 }
1069
1070 *result = tmp;
1071 return true;
1072
1073out_of_range:
1074 if (!errorOK)
1075 pg_log_error("value \"%s\" is out of range for type bigint", str);
1076 return false;
1077
1078invalid_syntax:
1079 if (!errorOK)
1080 pg_log_error("invalid input syntax for type bigint: \"%s\"", str);
1081 return false;
int64_t int64
Definition: c.h:535
int8_t int8
Definition: c.h:532
#define PG_INT64_MIN
Definition: c.h:596
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:293
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:262

References PG_INT64_MIN, pg_log_error, pg_mul_s64_overflow(), pg_sub_s64_overflow(), str, and unlikely.

Referenced by makeVariableValue().

syntax_error()

pg_noreturn void syntax_error ( const char *  source,
int  lineno,
const char *  line,
const char *  command,
const char *  msg,
const char *  more,
int  column 
)

Definition at line 5551 of file pgbench.c.

5555{
5557
5559
5560 printfPQExpBuffer(&buf, "%s:%d: %s", source, lineno, msg);
5561 if (more != NULL)
5562 appendPQExpBuffer(&buf, " (%s)", more);
5563 if (column >= 0 && line == NULL)
5564 appendPQExpBuffer(&buf, " at column %d", column + 1);
5565 if (command != NULL)
5566 appendPQExpBuffer(&buf, " in command \"%s\"", command);
5567
5568 pg_log_error("%s", buf.data);
5569
5571
5572 if (line != NULL)
5573 {
5574 fprintf(stderr, "%s\n", line);
5575 if (column >= 0)
5576 fprintf(stderr, "%*c error found here\n", column + 1, '^');
5577 }
5578
5579 exit(1);
#define fprintf(file, fmt, msg)
Definition: cubescan.l:21
static char * buf
Definition: pg_test_fsync.c:72
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:235
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:265
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:129

References appendPQExpBuffer(), buf, fprintf, initPQExpBuffer(), pg_log_error, printfPQExpBuffer(), source, and termPQExpBuffer().

Referenced by expr_yyerror_more(), ParseScript(), pg_lsn_in_safe(), process_backslash_command(), and string_to_uuid().

AltStyle によって変換されたページ (->オリジナル) /