Index: D:/sites/elle_root/kernel/classes/ezcontentobjecttreenode.php =================================================================== --- D:/sites/elle_root/kernel/classes/ezcontentobjecttreenode.php (revision 26501) +++ D:/sites/elle_root/kernel/classes/ezcontentobjecttreenode.php (working copy) @@ -1369,12 +1369,23 @@ $sqlDepthOperator = '='; } } - $nodeDepth += $depth; - $depthCond = ' and ezcontentobject_tree.depth '. $sqlDepthOperator . ' ' . $nodeDepth . ' '; + $nodeDepth += $depth; + $depthCond = ' and ezcontentobject_tree.depth '. $sqlDepthOperator . ' ' . $nodeDepth . ' '; } $outNotEqParentStr = " and ezcontentobject_tree.node_id != $nodeID "; - $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 );