@@ -1941,148 +1941,7 @@ doCustom(TState *thread, CState *st, StatsData *agg)
19411941 fprintf (stderr , "\n" );
19421942 }
19431943
1944- /*
1945- * Note: this section could be removed, as the same functionnality
1946- * is available through \set xxx random_gaussian(...)
1947- */
1948- if (pg_strcasecmp (argv [0 ], "setrandom" ) == 0 )
1949- {
1950- char * var ;
1951- int64 min ,
1952- max ;
1953- double parameter = 0 ;
1954- char res [64 ];
1955-
1956- if (* argv [2 ] == ':' )
1957- {
1958- if ((var = getVariable (st , argv [2 ] + 1 )) == NULL )
1959- {
1960- fprintf (stderr , "%s: undefined variable \"%s\"\n" ,
1961- argv [0 ], argv [2 ]);
1962- st -> ecnt ++ ;
1963- return true;
1964- }
1965- min = strtoint64 (var );
1966- }
1967- else
1968- min = strtoint64 (argv [2 ]);
1969-
1970- if (* argv [3 ] == ':' )
1971- {
1972- if ((var = getVariable (st , argv [3 ] + 1 )) == NULL )
1973- {
1974- fprintf (stderr , "%s: undefined variable \"%s\"\n" ,
1975- argv [0 ], argv [3 ]);
1976- st -> ecnt ++ ;
1977- return true;
1978- }
1979- max = strtoint64 (var );
1980- }
1981- else
1982- max = strtoint64 (argv [3 ]);
1983-
1984- if (max < min )
1985- {
1986- fprintf (stderr , "%s: \\setrandom maximum is less than minimum\n" ,
1987- argv [0 ]);
1988- st -> ecnt ++ ;
1989- return true;
1990- }
1991-
1992- /*
1993- * Generate random number functions need to be able to subtract
1994- * max from min and add one to the result without overflowing.
1995- * Since we know max > min, we can detect overflow just by
1996- * checking for a negative result. But we must check both that the
1997- * subtraction doesn't overflow, and that adding one to the result
1998- * doesn't overflow either.
1999- */
2000- if (max - min < 0 || (max - min ) + 1 < 0 )
2001- {
2002- fprintf (stderr , "%s: \\setrandom range is too large\n" ,
2003- argv [0 ]);
2004- st -> ecnt ++ ;
2005- return true;
2006- }
2007-
2008- if (argc == 4 || /* uniform without or with "uniform" keyword */
2009- (argc == 5 && pg_strcasecmp (argv [4 ], "uniform" ) == 0 ))
2010- {
2011- #ifdef DEBUG
2012- printf ("min: " INT64_FORMAT " max: " INT64_FORMAT " random: " INT64_FORMAT "\n" , min , max , getrand (thread , min , max ));
2013- #endif
2014- snprintf (res , sizeof (res ), INT64_FORMAT , getrand (thread , min , max ));
2015- }
2016- else if (argc == 6 &&
2017- ((pg_strcasecmp (argv [4 ], "gaussian" ) == 0 ) ||
2018- (pg_strcasecmp (argv [4 ], "exponential" ) == 0 )))
2019- {
2020- if (* argv [5 ] == ':' )
2021- {
2022- if ((var = getVariable (st , argv [5 ] + 1 )) == NULL )
2023- {
2024- fprintf (stderr , "%s: invalid parameter: \"%s\"\n" ,
2025- argv [0 ], argv [5 ]);
2026- st -> ecnt ++ ;
2027- return true;
2028- }
2029- parameter = strtod (var , NULL );
2030- }
2031- else
2032- parameter = strtod (argv [5 ], NULL );
2033-
2034- if (pg_strcasecmp (argv [4 ], "gaussian" ) == 0 )
2035- {
2036- if (parameter < MIN_GAUSSIAN_PARAM )
2037- {
2038- fprintf (stderr , "gaussian parameter must be at least %f (not \"%s\")\n" , MIN_GAUSSIAN_PARAM , argv [5 ]);
2039- st -> ecnt ++ ;
2040- return true;
2041- }
2042- #ifdef DEBUG
2043- printf ("min: " INT64_FORMAT " max: " INT64_FORMAT " random: " INT64_FORMAT "\n" ,
2044- min , max ,
2045- getGaussianRand (thread , min , max , parameter ));
2046- #endif
2047- snprintf (res , sizeof (res ), INT64_FORMAT ,
2048- getGaussianRand (thread , min , max , parameter ));
2049- }
2050- else if (pg_strcasecmp (argv [4 ], "exponential" ) == 0 )
2051- {
2052- if (parameter <= 0.0 )
2053- {
2054- fprintf (stderr ,
2055- "exponential parameter must be greater than zero (not \"%s\")\n" ,
2056- argv [5 ]);
2057- st -> ecnt ++ ;
2058- return true;
2059- }
2060- #ifdef DEBUG
2061- printf ("min: " INT64_FORMAT " max: " INT64_FORMAT " random: " INT64_FORMAT "\n" ,
2062- min , max ,
2063- getExponentialRand (thread , min , max , parameter ));
2064- #endif
2065- snprintf (res , sizeof (res ), INT64_FORMAT ,
2066- getExponentialRand (thread , min , max , parameter ));
2067- }
2068- }
2069- else /* this means an error somewhere in the parsing phase... */
2070- {
2071- fprintf (stderr , "%s: invalid arguments for \\setrandom\n" ,
2072- argv [0 ]);
2073- st -> ecnt ++ ;
2074- return true;
2075- }
2076-
2077- if (!putVariable (st , argv [0 ], argv [1 ], res ))
2078- {
2079- st -> ecnt ++ ;
2080- return true;
2081- }
2082-
2083- st -> listen = true;
2084- }
2085- else if (pg_strcasecmp (argv [0 ], "set" ) == 0 )
1944+ if (pg_strcasecmp (argv [0 ], "set" ) == 0 )
20861945 {
20871946 char res [64 ];
20881947 PgBenchExpr * expr = commands [st -> state ]-> expr ;
@@ -2880,43 +2739,7 @@ process_backslash_command(PsqlScanState sstate, const char *source)
28802739 start_offset ,
28812740 end_offset );
28822741
2883- if (pg_strcasecmp (my_command -> argv [0 ], "setrandom" ) == 0 )
2884- {
2885- /*--------
2886- * parsing:
2887- * \setrandom variable min max [uniform]
2888- * \setrandom variable min max (gaussian|exponential) parameter
2889- */
2890-
2891- if (my_command -> argc < 4 )
2892- syntax_error (source , lineno , my_command -> line , my_command -> argv [0 ],
2893- "missing arguments" , NULL , -1 );
2894-
2895- if (my_command -> argc == 4 || /* uniform without/with "uniform"
2896- * keyword */
2897- (my_command -> argc == 5 &&
2898- pg_strcasecmp (my_command -> argv [4 ], "uniform" ) == 0 ))
2899- {
2900- /* nothing to do */
2901- }
2902- else if ( /* argc >= 5 */
2903- (pg_strcasecmp (my_command -> argv [4 ], "gaussian" ) == 0 ) ||
2904- (pg_strcasecmp (my_command -> argv [4 ], "exponential" ) == 0 ))
2905- {
2906- if (my_command -> argc < 6 )
2907- syntax_error (source , lineno , my_command -> line , my_command -> argv [0 ],
2908- "missing parameter" , NULL , -1 );
2909- else if (my_command -> argc > 6 )
2910- syntax_error (source , lineno , my_command -> line , my_command -> argv [0 ],
2911- "too many arguments" , NULL ,
2912- offsets [6 ] - start_offset );
2913- }
2914- else /* unrecognized distribution argument */
2915- syntax_error (source , lineno , my_command -> line , my_command -> argv [0 ],
2916- "unexpected argument" , my_command -> argv [4 ],
2917- offsets [4 ] - start_offset );
2918- }
2919- else if (pg_strcasecmp (my_command -> argv [0 ], "sleep" ) == 0 )
2742+ if (pg_strcasecmp (my_command -> argv [0 ], "sleep" ) == 0 )
29202743 {
29212744 if (my_command -> argc < 2 )
29222745 syntax_error (source , lineno , my_command -> line , my_command -> argv [0 ],
0 commit comments