diff options
author | mattab <matthieu.aubry@gmail.com> | 2015-06-18 03:00:55 +0300 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2015-06-18 03:00:55 +0300 |
commit | 937e73dff91b3b8d97380c3648ba29d3e850a10c (patch) | |
tree | 00bab3ad8ff24b98e5341039c7757b1c943b893f /core/Segment | |
parent | abefedee76c37450b011a5a29cb9beec1aceff94 (diff) |
when we know a segment won't match any row, replace the SQL sub-expression by (1 = 0)
Segment SQL generator: un-needed joins on log_link_visit_action are removed, making the query a bit faster
Diffstat (limited to 'core/Segment')
-rw-r--r-- | core/Segment/SegmentExpression.php | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/core/Segment/SegmentExpression.php b/core/Segment/SegmentExpression.php index 3fcf232a14..07b535f8c7 100644 --- a/core/Segment/SegmentExpression.php +++ b/core/Segment/SegmentExpression.php @@ -40,6 +40,8 @@ class SegmentExpression const INDEX_BOOL_OPERATOR = 0; const INDEX_OPERAND = 1; + const SQL_WHERE_DO_NOT_MATCH_ANY_ROW = "(1 = 0)"; + public function __construct($string) { $this->string = $string; @@ -138,13 +140,21 @@ class SegmentExpression $operator = $leaf[self::INDEX_BOOL_OPERATOR]; $operandDefinition = $leaf[self::INDEX_OPERAND]; - $operand = $this->getSqlMatchFromDefinition($operandDefinition, $availableTables); - if ($operand[1] !== null) { - $this->valuesBind[] = $operand[1]; + // in case we know already the segment won't match any row... + if($operandDefinition === array() ) { // see getCleanedExpression() + $operand = self::SQL_WHERE_DO_NOT_MATCH_ANY_ROW; + + } else { + $operand = $this->getSqlMatchFromDefinition($operandDefinition, $availableTables); + + if ($operand[1] !== null) { + $this->valuesBind[] = $operand[1]; + } + + $operand = $operand[0]; } - $operand = $operand[0]; $sqlSubExpressions[] = array( self::INDEX_BOOL_OPERATOR => $operator, self::INDEX_OPERAND => $operand, @@ -381,3 +391,4 @@ class SegmentExpression ); } } + |