Where is it authoritatively documented, what does the syntax (expr, expr, ...) do?

In another question , it was pointed out that the following conditional criteria are equivalent:

(a,b,c,d) != (1,2,3,4)                  -- (1)
(a != 1 OR b != 2 OR c != 3 OR d != 4)  -- (2)

The parsing rule for the construct (a,b,c,d)(note that this is not a subquery) simple_exprand there is a grammar statement there .

However, I cannot find any documentation whatsoever for the behavior of the above conditional (1), and my gut tells me that it is not equivalent (2).

  • Where is the behavior of this expression described in this context?

(Answers must refer to authoritative sources or state that nothing exists and that we should infer the behavior of an expression only through empirical data.)

+4
source share
4 answers

There is potentially conflicting relevant information here that talks about the implicit construction of a “string” for each operand and the podium for a series of comparisons.

It only says what is ANDused for sorting:

String constructors are legal in other contexts. For example, the following two statements are semantically equivalent:

SELECT * FROM t1 WHERE (column1,column2) = (1,1);
SELECT * FROM t1 WHERE column1 = 1 AND column2 = 1;

This has no specifics, although PostgreSQL is a bit more accurate :

, ; , ; (null).

MySQL = != (, , !((a = 1) AND (b = 2) ...) ), , , PostgreSQL MySQL ( !).

-2

, , : http://dev.mysql.com/doc/refman/5.0/en/any-in-some-subqueries.html

AND . (, .)

-: "exp1 ( ), exp2 ( )". , ANY ( ) exp1 exp2 , exp .

, , .

: ! http://dev.mysql.com/doc/refman/5.0/en/row-subqueries.html

Edit2: , , , =, , , ANY .

+3

. , , =, ​​ , .

, ( comparators Arg_comparator::set_compare_func , ).

int Arg_comparator::compare_row()
{
  int res= 0;
  bool was_null= 0;
  (*a)->bring_value();
  (*b)->bring_value();

  if ((*a)->null_value || (*b)->null_value)
  {
    owner->null_value= 1;
    return -1;
  }

  uint n= (*a)->cols();
  for (uint i= 0; i<n; i++)
  {
    res= comparators[i].compare();
    /* Aggregate functions don't need special null handling. */
    if (owner->null_value && owner->type() == Item::FUNC_ITEM)
    {
      // NULL was compared
      switch (((Item_func*)owner)->functype()) {
      case Item_func::NE_FUNC:
        break; // NE never aborts on NULL even if abort_on_null is set
      case Item_func::LT_FUNC:
      case Item_func::LE_FUNC:
      case Item_func::GT_FUNC:
      case Item_func::GE_FUNC:
        return -1; // <, <=, > and >= always fail on NULL
      default: // EQ_FUNC
        if (((Item_bool_func2*)owner)->abort_on_null)
          return -1; // We do not need correct NULL returning
      }
      was_null= 1;
      owner->null_value= 0;
      res= 0;  // continue comparison (maybe we will meet explicit difference)
    }
    else if (res)
      return res;
  }
  if (was_null)
  {
    /*
      There was NULL(s) in comparison in some parts, but there was no
      explicit difference in other parts, so we have to return NULL.
    */
    owner->null_value= 1;
    return -1;
  }
  return 0;
}

, . - , . - null, , , !=.

, . , true, unknown.

SELECT (1,2) <> (1,2), 
       (1,NULL,2) <> (1,NULL,2), 
       (1,NULL,2) <> (1,NULL,3)
FROM dual

+----------------+--------------------------+--------------------------+
| (1,2) <> (1,2) | (1,NULL,2) <> (1,NULL,2) | (1,NULL,2) <> (1,NULL,3) |
+----------------+--------------------------+--------------------------+
|              0 | NULL                     |                        1 |
+----------------+--------------------------+--------------------------+

null, 0, , .

+3

, (a,b) ROW(a,b)

The expressions (1,2) and ROW (1,2) are sometimes called string constructors. These are two equivalents. The row constructor and the row returned by the subquery must contain the same number of values.

http://dev.mysql.com/doc/refman/5.0/en/row-subqueries.html

To answer your comment, these expressions seem equivalent:

(a,b) = (x,y)  ~ a=x AND b=y
(a,b) != (x,y) ~ a!=x OR b!=y

See also http://en.wikipedia.org/wiki/De_Morgan%27s_laws

+2
source

All Articles