Skip to content

Commit

Permalink
MySQL STRAIGHT_JOIN implementation (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlostanisic authored and kazsaj committed Mar 24, 2024
1 parent 41f84ba commit e24634b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions library/Zend/Db/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Zend_Db_Select
const FULL_JOIN = 'full join';
const CROSS_JOIN = 'cross join';
const NATURAL_JOIN = 'natural join';
const STRAIGHT_JOIN = 'straight_join';

const SQL_WILDCARD = '*';
const SQL_SELECT = 'SELECT';
Expand Down Expand Up @@ -166,6 +167,7 @@ class Zend_Db_Select
self::FULL_JOIN,
self::CROSS_JOIN,
self::NATURAL_JOIN,
self::STRAIGHT_JOIN,
];

/**
Expand Down Expand Up @@ -489,6 +491,30 @@ public function joinNatural($name, $cols = self::SQL_WILDCARD, $schema = null)
{
return $this->_join(self::NATURAL_JOIN, $name, null, $cols, $schema);
}

/**
* Add a STRAIGHT_JOIN table and columns to the query
* In MySQL an STRAIGHT_JOIN scans and combines matching rows
* (if specified any condition) which are stored in associated tables
* otherwise it behaves like an INNER JOIN or JOIN of without any condition.
* STRAIGHT_JOIN is similar to JOIN,
* except that the left table is always read before the right table.
* This can be used for those (few) cases for which the join optimizer
* puts the tables in the wrong order.
*
* The $name and $cols parameters follow the same logic
* as described in the from() method.
*
* @param array|string|Zend_Db_Expr $name The table name.
* @param string $cond Join on this condition.
* @param array|string $cols The columns to select from the joined table.
* @param string $schema The database name to specify, if any.
* @return Zend_Db_Select This Zend_Db_Select object.
*/
public function joinStraight($name, $cond, $cols = self::SQL_WILDCARD, $schema = null)
{
return $this->_join(self::STRAIGHT_JOIN, $name, $cond, $cols, $schema);
}

/**
* Adds a WHERE condition to the query by AND.
Expand Down

0 comments on commit e24634b

Please sign in to comment.