N°3660 - Fix JOIN without condition on child joined table is ignored (check done in optimizer)

This commit is contained in:
Eric
2021-02-03 15:58:54 +01:00
parent 2f0e7c6d29
commit e06996a2e4
4 changed files with 19 additions and 11 deletions

View File

@@ -331,4 +331,12 @@ class OQLJoin
return $this->sRightField;
}
/**
* @return string
*/
public function GetLeftField()
{
return $this->sLeftField;
}
}

View File

@@ -294,13 +294,6 @@ class OQLClassTreeBuilder
$oClassExpr = new FieldExpression($sClassAttCode, $this->sClassAlias);
$oClassRestriction = new BinaryExpression($oClassExpr, 'IN', $oClassListExpr);
$oQBContextExpressions->AddCondition($oClassRestriction);
} elseif (($oKeyAttDef instanceof AttributeExternalKey) && $sKeyClass != $oKeyAttDef->GetTargetClass()) {
$sClassAttCode = 'finalclass';
$oClassListExpr = ListExpression::FromScalars(MetaModel::EnumChildClasses($sKeyClass,
ENUM_CHILD_CLASSES_ALL));
$oClassExpr = new FieldExpression($sClassAttCode, $sKeyClassAlias);
$oClassRestriction = new BinaryExpression($oClassExpr, 'IN', $oClassListExpr);
$oQBContextExpressions->AddCondition($oClassRestriction);
}
// Translate prior to recursing

View File

@@ -50,8 +50,15 @@ class OQLClassTreeOptimizer
{
if ($oJoin->IsOutbound())
{
// The join is not used, remove from tree
$oCurrentClassNode->RemoveJoin($sLeftKey, $index);
// If joined class in not the same class than the external key target class
// then the join cannot be removed because it is used to filter the request
$sJoinedClass = $oJoin->GetOOQLClassNode()->GetNodeClass();
$sExtKeyAttCode = $oJoin->GetLeftField();
$oExtKeyAttDef = MetaModel::GetAttributeDef($oCurrentClassNode->GetNodeClass(), $sExtKeyAttCode);
if ($sJoinedClass == $oExtKeyAttDef->GetTargetClass()) {
// The join is not used, remove from tree
$oCurrentClassNode->RemoveJoin($sLeftKey, $index);
}
}
else
{

View File

@@ -441,8 +441,8 @@ class OQLTest extends ItopDataTestCase
"SELECT `U` FROM `UserRequest` AS `U`
INNER JOIN `lnkContactToTicket` AS `l`
ON `U`.`id` = `l`.`ticket_id`
INNER JOIN `Contact` AS `T_Contact`
ON `l`.`contact_id` = `T_Contact`.`id`",
INNER JOIN `Team` AS `T`
ON `l`.`contact_id` = `T`.`id`",
],
'Bug 3660 2' => [
"SELECT UserRequest AS U