--- ezcontentobjecttreenode.php Thu Nov 22 12:18:09 2007 +++ ezcontentobjecttreenode_faster.php Thu Nov 22 15:52:48 2007 @@ -1290,7 +1290,7 @@ /*! \a static */ - static function createPathConditionSQLString( $nodePath, $nodeDepth, $depth, $depthOperator ) + static function createPathConditionSQLString( $nodePath, $nodeDepth, $depth, $depthOperator, $nodeID ) { $pathCondition = ''; $depthCondition = ''; @@ -1326,7 +1326,18 @@ $depthCondition = ' ezcontentobject_tree.depth '. $sqlDepthOperator . ' ' . $nodeDepth . ' and '; } - $pathCondition = " ezcontentobject_tree.path_string like '$nodePath%' and $depthCondition "; + //$pathCondition = " ezcontentobject_tree.path_string like '$nodePath%' and $depthCondition "; + if ( $depth === 1 and ( $sqlDepthOperator === '=' or $sqlDepthOperator === '<=' ) ) + { + // Special SQL optimization case: we are searching for direct children of a node. + // Instead of going for a like operator on path_string column, we go for an equality operator on parent_node_id column + // NB: IF we where sure that ther is no node that is parent of self, we could remove $outNotEqParentStr altogether + $pathCondition = " ezcontentobject_tree.parent_node_id = $nodeID "; + } + else + { + $pathCondition = " ezcontentobject_tree.path_string like '$nodePath%' and $depthCondition "; + } return $pathCondition; } @@ -1380,7 +1391,18 @@ } $outNotEqParentStr = " and ezcontentobject_tree.node_id != $nodeID "; - $sqlPartForOneNodeList[] = " ( ezcontentobject_tree.path_string like '$nodePath%' $depthCond $outNotEqParentStr ) "; + //$sqlPartForOneNodeList[] = " ( ezcontentobject_tree.path_string like '$nodePath%' $depthCond $outNotEqParentStr ) "; + if ( $depth === 1 and ( $sqlDepthOperator === '=' or $sqlDepthOperator === '<=' ) ) + { + // Special SQL optimization case: we are searching for direct children of a node. + // Instead of going for a like operator on path_string column, we go for an equality operator on parent_node_id column + // NB: IF we where sure that ther is no node that is parent of self, we could remove $outNotEqParentStr altogether + $sqlPartForOneNodeList[] = " ( ezcontentobject_tree.parent_node_id = $nodeID $outNotEqParentStr ) "; + } + else + { + $sqlPartForOneNodeList[] = " ( ezcontentobject_tree.path_string like '$nodePath%' $depthCond $outNotEqParentStr ) "; + } $outNotEqParentStr = ''; } $outPathConditionStr = implode( ' or ', $sqlPartForOneNodeList ); @@ -1403,7 +1425,7 @@ } $outNotEqParentStr = eZContentObjectTreeNode::createNotEqParentSQLString( $nodeID, $depth, $depthOperator ); - $outPathConditionStr = eZContentObjectTreeNode::createPathConditionSQLString( $nodePath, $nodeDepth, $depth, $depthOperator ); + $outPathConditionStr = eZContentObjectTreeNode::createPathConditionSQLString( $nodePath, $nodeDepth, $depth, $depthOperator, $nodeID ); } return true;