Processing Relational Expressions

The processing of a where clause is driven by the left-hand side of relational expressions in several different ways.

  • Creating efficient SQL for a relational expression depends on the left-hand side being a select keyword that can be mapped to SQL AND the right hand side being a constant. The only exception to the rule that the right-hand-side must be a constant are the specific expressions revision == first and revision == last.
  • The left hand side (if it is a select keyword) also drives the datatype of the expression. That is, if the left-hand side refers to an integer attribute, 3DSpace attempts to interpret the right-hand side as an integer; if the left-hand side is a date, it tries to interpret the right-hand side as a date.
  • When the left-hand side represents a string in the database that is SQL convertible (such as attribute[Synopsis]), SQL is constructed to request the database server to return objects which match the right-hand side. In doing so, the server will treat the database values as literal strings with no wildcards. Wildcard matching only applies to the right-hand side.
  • However, when the left-hand side represents a string in the database that is not SQL convertible (such as “description, or state[S].signature[SIG].signer), the system must read the value into memory for each object and do a match. In this case, * and ? within the read values will be treated as wildcards. This is also true in the case where .value is appended (such as attribute[Synopsis].value), since that makes the clause not SQL convertible.
  • Only the right-hand side is interpreted to include wildcards (unless you use == or !==).
  • When used with the Equal and Not Equal operators (==, !=) in the where clause, the system treats the wildcard characters “?” and “*” as literal characters on both sides of the expression. Do not use these characters when querying using the Equal or Not Equal operators. On the other hand, MQL interprets “?” and “*” as wildcards when used with the four Match operators and when used in the Type, Name, or Revision fields of the query. For example, if you type the following query:
    temp query bus * A*B *

    MQL returns all objects that start with A and end with B. However, if you use the equality operator in the where clause, as follows:

    temp query bus * * * where name == A*B

    MQL looks for the literal A*B as the entire object name rather than treating the * as a wildcard.