Skip to content

RandomQueryGeneratorQueryProperties

philip-stoev edited this page Jul 17, 2012 · 1 revision

Category:RandomQueryGenerator

Rationale

It is difficult to do purely functional testing on a random query workload, and validate the result set of every individual query, especially when the queries are executed concurrently.

Nevertheless, there are cases where the queries being generated have some generic properties that should be validated after each query is run.

Tagging

In order to make use of this facility, put the desired propery inside /* */ comments and place it in the grammar file. This way, it will get added to each query that is generated from the particular rule. The property will also be visible in the server query log. For example:

 select_item:
    _field |
    COUNT ( _field ) /* RESULTSET_HAS_ZERO_OR_ONE_ROWS */;

In this example, if the generated queries happens to have COUNT, it is also going to be tagged with /* RESULTSET_HAS_ZERO_OR_ONE_ROWS */. If the RQG detects that you have tagged queries in your grammar, it will enable the QueryProperties Validator in order to validate them.

In this particular case, COUNT() should cause query to never return more than one row, which will be checked because the query is tagged accordingly.

Available Properties

  • RESULTSET_HAS_SAME_DATA_IN_EVERY_ROW
Ensures there are no duplicates in the result set. For example, a query containing DISTINCT would have the RESULTSET_HAS_SAME_DATA_IN_EVERY_ROW property.
  • RESULTSET_IS_SINGLE_INTEGER_ONE
Ensures that the query result set is just a single row, single column containing the value of 1. This is useful for queries that perform various checks and then return 1 on success.
  • RESULTSET_HAS_ZERO_OR_ONE_ROWS, RESULTSET_HAS_ONE_ROW
Ensures that the query returned one or zero rows. This is useful to validate aggregates and DISTINCT queries.
  • ERROR_NNN
Ensures that the query has failed with this particular error code. The NNN must be numeric at this time and each query is only allowed a single such tag. Use ERROR_0 to indicate that the query should have succeeded.
  • QUERY_IS_REPLICATION_SAFE
Ensures that the query did not produce the "1592 Statement may not be safe to log in statement format" note in SHOW WARNINGS.