PostgreSQL Source Code  git master
pgbench.h File Reference
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
 

Macros

#define yyscan_t   void *
 

Typedefs

typedef enum PgBenchExprType PgBenchExprType
 
typedef enum PgBenchFunction PgBenchFunction
 
typedef struct PgBenchExpr PgBenchExpr
 
typedef struct PgBenchExprLink PgBenchExprLink
 
typedef struct PgBenchExprList PgBenchExprList
 

Enumerations

enum  PgBenchValueType {
  PGBT_NO_VALUE, PGBT_NULL, PGBT_INT, PGBT_DOUBLE,
  PGBT_BOOLEAN
}
 
enum  PgBenchExprType { ENODE_CONSTANT, ENODE_VARIABLE, ENODE_FUNCTION }
 
enum  PgBenchFunction {
  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
}
 

Functions

int expr_yyparse (yyscan_t yyscanner)
 
int expr_yylex (union YYSTYPE *lvalp, yyscan_t yyscanner)
 
void expr_yyerror (yyscan_t yyscanner, const char *str) pg_attribute_noreturn()
 
void expr_yyerror_more (yyscan_t yyscanner, const char *str, const char *more) pg_attribute_noreturn()
 
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)
 
int expr_scanner_offset (PsqlScanState state)
 
char * expr_scanner_get_substring (PsqlScanState state, int start_offset, int end_offset, bool chomp)
 
int expr_scanner_get_lineno (PsqlScanState state, int offset)
 
void syntax_error (const char *source, int lineno, const char *line, const char *cmd, const char *msg, const char *more, int col) pg_attribute_noreturn()
 
bool strtoint64 (const char *str, bool errorOK, int64 *pi)
 
bool strtodouble (const char *str, bool errorOK, double *pd)
 

Variables

PgBenchExprexpr_parse_result
 

Macro Definition Documentation

◆ yyscan_t

#define yyscan_t   void *

Definition at line 23 of file pgbench.h.

Typedef Documentation

◆ PgBenchExpr

typedef struct PgBenchExpr PgBenchExpr

Definition at line 105 of file pgbench.h.

◆ PgBenchExprLink

Definition at line 106 of file pgbench.h.

◆ PgBenchExprList

Definition at line 107 of file pgbench.h.

◆ PgBenchExprType

◆ PgBenchFunction

Enumeration Type Documentation

◆ PgBenchExprType

Enumerator
ENODE_CONSTANT 
ENODE_VARIABLE 
ENODE_FUNCTION 

Definition at line 57 of file pgbench.h.

◆ 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 

Definition at line 65 of file pgbench.h.

66 {
78  PGBENCH_PI,
80  PGBENCH_LN,
88  PGBENCH_OR,
95  PGBENCH_EQ,
96  PGBENCH_NE,
97  PGBENCH_LE,
98  PGBENCH_LT,
99  PGBENCH_IS,
100  PGBENCH_CASE,
PgBenchFunction
Definition: pgbench.h:65

◆ PgBenchValueType

Enumerator
PGBT_NO_VALUE 
PGBT_NULL 
PGBT_INT 
PGBT_DOUBLE 
PGBT_BOOLEAN 

Definition at line 34 of file pgbench.h.

35 {
37  PGBT_NULL,
38  PGBT_INT,
41  /* add other types here */
PgBenchValueType
Definition: pgbench.h:34

Function Documentation

◆ expr_lex_one_word()

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

◆ expr_scanner_finish()

void expr_scanner_finish ( yyscan_t  yyscanner)

◆ expr_scanner_get_lineno()

int expr_scanner_get_lineno ( PsqlScanState  state,
int  offset 
)

◆ expr_scanner_get_substring()

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

◆ expr_scanner_init()

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

◆ expr_scanner_offset()

int expr_scanner_offset ( PsqlScanState  state)

◆ expr_yyerror()

void expr_yyerror ( yyscan_t  yyscanner,
const char *  str 
)

◆ expr_yyerror_more()

void expr_yyerror_more ( yyscan_t  yyscanner,
const char *  str,
const char *  more 
)

◆ expr_yylex()

int expr_yylex ( union YYSTYPE *  lvalp,
yyscan_t  yyscanner 
)

◆ expr_yyparse()

int expr_yyparse ( yyscan_t  yyscanner)

◆ strtodouble()

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

Definition at line 802 of file pgbench.c.

References pg_log_error, and unlikely.

Referenced by makeVariableValue().

803 {
804  char *end;
805 
806  errno = 0;
807  *dv = strtod(str, &end);
808 
809  if (unlikely(errno != 0))
810  {
811  if (!errorOK)
812  pg_log_error("value \"%s\" is out of range for type double", str);
813  return false;
814  }
815 
816  if (unlikely(end == str || *end != '\0'))
817  {
818  if (!errorOK)
819  pg_log_error("invalid input syntax for type double: \"%s\"", str);
820  return false;
821  }
822  return true;
823 }
#define pg_log_error(...)
Definition: logging.h:79
#define unlikely(x)
Definition: c.h:206

◆ strtoint64()

bool strtoint64 ( const char *  str,
bool  errorOK,
int64 *  pi 
)

Definition at line 731 of file pgbench.c.

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

Referenced by makeVariableValue().

732 {
733  const char *ptr = str;
734  int64 tmp = 0;
735  bool neg = false;
736 
737  /*
738  * Do our own scan, rather than relying on sscanf which might be broken
739  * for long long.
740  *
741  * As INT64_MIN can't be stored as a positive 64 bit integer, accumulate
742  * value as a negative number.
743  */
744 
745  /* skip leading spaces */
746  while (*ptr && isspace((unsigned char) *ptr))
747  ptr++;
748 
749  /* handle sign */
750  if (*ptr == '-')
751  {
752  ptr++;
753  neg = true;
754  }
755  else if (*ptr == '+')
756  ptr++;
757 
758  /* require at least one digit */
759  if (unlikely(!isdigit((unsigned char) *ptr)))
760  goto invalid_syntax;
761 
762  /* process digits */
763  while (*ptr && isdigit((unsigned char) *ptr))
764  {
765  int8 digit = (*ptr++ - '0');
766 
767  if (unlikely(pg_mul_s64_overflow(tmp, 10, &tmp)) ||
768  unlikely(pg_sub_s64_overflow(tmp, digit, &tmp)))
769  goto out_of_range;
770  }
771 
772  /* allow trailing whitespace, but not other trailing chars */
773  while (*ptr != '\0' && isspace((unsigned char) *ptr))
774  ptr++;
775 
776  if (unlikely(*ptr != '\0'))
777  goto invalid_syntax;
778 
779  if (!neg)
780  {
781  if (unlikely(tmp == PG_INT64_MIN))
782  goto out_of_range;
783  tmp = -tmp;
784  }
785 
786  *result = tmp;
787  return true;
788 
789 out_of_range:
790  if (!errorOK)
791  pg_log_error("value \"%s\" is out of range for type bigint", str);
792  return false;
793 
794 invalid_syntax:
795  if (!errorOK)
796  pg_log_error("invalid input syntax for type bigint: \"%s\"", str);
797  return false;
798 }
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
#define pg_log_error(...)
Definition: logging.h:79
#define PG_INT64_MIN
Definition: c.h:452
signed char int8
Definition: c.h:353
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
#define unlikely(x)
Definition: c.h:206

◆ syntax_error()

void syntax_error ( const char *  source,
int  lineno,
const char *  line,
const char *  cmd,
const char *  msg,
const char *  more,
int  col 
)

Definition at line 4369 of file pgbench.c.

References appendPQExpBuffer(), buf, PQExpBufferData::data, fprintf, initPQExpBuffer(), pg_log_fatal, printfPQExpBuffer(), and termPQExpBuffer().

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

4372 {
4374 
4375  initPQExpBuffer(&buf);
4376 
4377  printfPQExpBuffer(&buf, "%s:%d: %s", source, lineno, msg);
4378  if (more != NULL)
4379  appendPQExpBuffer(&buf, " (%s)", more);
4380  if (column >= 0 && line == NULL)
4381  appendPQExpBuffer(&buf, " at column %d", column + 1);
4382  if (command != NULL)
4383  appendPQExpBuffer(&buf, " in command \"%s\"", command);
4384 
4385  pg_log_fatal("%s", buf.data);
4386 
4387  termPQExpBuffer(&buf);
4388 
4389  if (line != NULL)
4390  {
4391  fprintf(stderr, "%s\n", line);
4392  if (column >= 0)
4393  fprintf(stderr, "%*c error found here\n", column + 1, '^');
4394  }
4395 
4396  exit(1);
4397 }
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define fprintf
Definition: port.h:197
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
#define pg_log_fatal(...)
Definition: logging.h:75

Variable Documentation

◆ expr_parse_result

PgBenchExpr* expr_parse_result