Content node lists: the query, DISTINCT and NodeListDistinct
This page explains how Exponential reads a list of content nodes from the database: the query behind
fetch( 'content', 'list' ), fetch( 'content', 'tree' ), their _count fetches and the PHP methods
eZContentObjectTreeNode::subTreeByNodeID(), subTreeCountByNodeID() and subTreeMultiPaths(). It says when that
query asks the database for SELECT DISTINCT, why it no longer always does, what that is worth, and how the setting
site.ini [ContentSettings] NodeListDistinct brings the old query back.
It is written for administrators, operators and developers who read slow query logs. Every statement below was checked against the code of this repository on 3 December 2026; the files are named in References.
Guides · Related: Operating a site · Benchmarking · Upgrade notes · German · Changelog 6.0.15
In short
- Since 3 December 2026 (the 6.0.15 line) a node list query has
SELECT DISTINCTonly where a join in it can give a node more than one row. The plain list, the one almost every page asks for, no longer has it, and its count usesCOUNT(*)instead ofCOUNT(DISTINCT node_id). - The lists are the same: the same nodes, in the same order, with the same counts. DISTINCT removed nothing from those queries; it only made MariaDB and MySQL collect every matching row in a temporary table before they could sort and apply the limit.
- The gain is large where a list reads few rows of a big subtree: a forum's previous/next lookup went from 1.85 s (slow log, under load) or 0.16 to 0.34 s (a scratch copy) to 1 or 2 ms; paged archive lists, sitemaps and the "latest" lists of big sites are 1.6 to 2.5 times faster (see Measured).
NodeListDistinct=alwaysinsettings/override/site.ini.append.phprestores the old queries at once, for the whole site or one siteaccess. Clear the INI cache (php bin/php/ezcache.php --clear-tag=ini) and reload PHP-FPM or restart Velocity, like any other setting.
1. The query
A node list joins four tables, whatever its parameters:
| Table | Joined on | Rows per node |
|---|---|---|
ezcontentobject_tree | the list's own rows, one per node | 1 |
ezcontentobject | id = ezcontentobject_tree.contentobject_id (primary key) | 1 |
ezcontentclass | id = ezcontentobject.contentclass_id AND version = 0 (primary key id, version) | 1 |
ezcontentobject_name | the object and the node's version, with the language condition of eZContentLanguage::sqlFilter() | at most 1, see below |
The parameters then add conditions to the WHERE clause (path, depth, class filter, visibility, main node only, the
object name filter, attribute filters on node and object columns, the read permission) and, for some of them, more
tables.
Why the name join gives one row
ezcontentobject_name has one row per object, version and translation. The language condition lets through, for each
version, the row of the most prioritized language the object has, or the row of its always available language when
it has none of the prioritized ones:
- Each prioritized language gets a weight, a power of two, the first language the highest. A name row passes only when the weight of its own language is more than the weights of the other prioritized languages the object has. The weight of a higher language is more than the sum of every lower weight and the always available bit together, so the rows of two prioritized languages can never both pass.
- A row of a language that is not prioritized has the weight 0. It passes only with the always available bit
(
language_id & 1) and only when the object has no prioritized language at all. That bit is set on one name row of a version: the row of the object's initial language.
So each version yields one name row, or none (an object without any language of the site, which the list leaves out as before). On 3 December 2026 four production databases were checked for the rule's two data assumptions: no version had two name rows with the always available bit, and no name row carried two language bits (257,299, 659,780, 72,747 and 16,329 name rows). Should a database ever break that rule, DISTINCT would not have helped either: the extra row carries another name and translation, so DISTINCT, which removes only identical rows, kept it too.
What keeps DISTINCT
eZContentObjectTreeNode::nodeListNeedsDistinct() keeps SELECT DISTINCT (and COUNT(DISTINCT node_id)) when the
query has any of these, because each joins another table that can give a node more than one row:
| Parameter | What it joins |
|---|---|
SortBy attribute | ezcontentobject_attribute (and the datatype's own table for a custom sort) |
SortBy class_name | ezcontentclass_name |
SortBy state | ezcobj_state, ezcobj_state_link |
AttributeFilter on an attribute or class_name | ezcontentobject_attribute, ezcontentclass_name |
ExtendedAttributeFilter (any: its tables, joins, columns or GROUP BY) | whatever the filter's handler adds (eZ Tags, relations, keywords) |
GroupBy | the GROUP BY of the list |
| a Group limitation in the user's read policies | a temporary table of the owners in the user's groups |
| a StateGroup limitation in the user's read policies | ezcobj_state_link, ezcobj_state_group, ezcobj_state |
A builder part that is not the array its builder returns also keeps DISTINCT: what is not known is not proven.
subTreeMultiPaths() keeps DISTINCT when one of its paths has any of the above, or when the list has a GROUP BY.
What does not
These only add conditions to the WHERE clause, which can drop a row but never repeat one, and the query leaves
DISTINCT out with them:
Depth,DepthOperator,Limit,Offset,MainNodeOnly,IgnoreVisibility,ClassFilterTypeandClassFilterArray,ObjectNameFilter,Languageand the site's language list;SortByonpath,path_string,published,modified,modified_subnode,section,node_id,contentobject_id,depth,class_identifier,priority,visibility,name;AttributeFilteron node and object columns:modified_subnode,published,modified,section,depth,priority,owner,visibility,name,path,node_id,contentobject_id,class_identifier, andstate(a sub-select in theWHEREclause);- the read policies' limitations Subtree, Node, Class, Section, Owner, User_Section, User_Subtree, and the conditions an extension's limitation handler writes;
- several locations of one object: they are several nodes with their own
node_id, which DISTINCT never merged.
The count of GroupByParent (the children of each node) groups the nodes by their parent; that groups rows, it does
not repeat them, and the count uses COUNT(*) there too.
2. The setting
[ContentSettings]
NodeListDistinct=auto| Value | Effect |
|---|---|
auto (default; also when the setting is missing) | DISTINCT and COUNT(DISTINCT node_id) only for the query shapes listed under What keeps DISTINCT |
always | DISTINCT in every node list query and COUNT(DISTINCT node_id) in every count, as every release before 6.0.15 |
Any other value counts as always.
Going back to the old queries
Should a list ever differ, or a database plan the new query worse than the old one:
# settings/override/site.ini.append.php (or a siteaccess's site.ini.append.php for one siteaccess)
# [ContentSettings]
# NodeListDistinct=always
php bin/php/ezcache.php --clear-tag=ini --allow-root-user
systemctl reload <the PHP-FPM service of the site> # Apache with PHP-FPM
./console exp:velocity restart # Velocity
php bin/php/ezcache.php --clear-id=content --allow-root-user # pages cached with the listphp bin/php/console exp:ini get site.ini/ContentSettings/NodeListDistinct siteaccess:<name> shows which value a
siteaccess reads.
Ties in the sort order
A list sorted by a key that several nodes share (the same published date, the same priority) comes out in the
order the database finds those nodes, with or without DISTINCT; no setting ever fixed that order. Without DISTINCT the
database may walk an index instead of a temporary table, so nodes that tie on every sort key can come in another order
than before. A list that pages through such nodes and needs a stable order adds a last sort key that is unique:
array( array( 'published', false ), array( 'node_id', false ) ).
Measured
The slowest statements of the MariaDB slow log of 3 December 2026 on the sites database server, run on unreplicated
scratch copies of their content tables (ezcontentobject_tree, ezcontentobject, ezcontentobject_name,
ezcontentclass), three runs each, with DISTINCT (before) and without (after). Every one of them is the plain shape:
four tables, the permission condition in the WHERE clause. For each, the full result without LIMIT had as many
rows as distinct nodes, so leaving DISTINCT out changed no result.
| # | Site | List | Slow log: calls, average | Before (DISTINCT) | After | Rows read |
|---|---|---|---|---|---|---|
| 1 | share.exponential.earth | forum topic, previous: modified_subnode < X, ORDER BY modified_subnode DESC, node_id, LIMIT 1 | 13,479 calls, 1.894 s | 0.163 s | 0.002 s | 1 of 1,649 |
| 2 | share.exponential.earth | forum topic, next: modified_subnode > X, ascending, LIMIT 1 | 9,491 calls, 1.841 s | 0.340 s | 0.001 s | 1 of 4,450 |
| 3 | site B | class 38 below /1/2/, ORDER BY published DESC LIMIT 46145, 300 | 2,764 calls, 2.132 s | 1.799 s | 1.087 s | 300 of 56,758 |
| 4 | site C | ORDER BY published DESC LIMIT 4038, 1 | 1,501 calls, 1.504 s | 0.099 s | 0.039 s | 1 of 4,338 |
| 5 | share.exponential.earth | whole tree by path, LIMIT 0, 49000 (sitemap) | 626 calls, 2.988 s | 2.584 s | 1.053 s | 49,000 of 70,358 |
| 6 | share.exponential.earth | subTreeMultiPaths(), ORDER BY published DESC LIMIT 30 | 460 calls, 3.874 s | 3.153 s | 1.566 s | 30 of 89,285 |
| 7 | site D | ORDER BY priority DESC LIMIT 17 | 692 calls, 2.173 s | 0.002 s | 0.002 s | 17 of 27 |
| 8 | share.exponential.earth | ORDER BY modified DESC, a few rows | 361 calls, 3.649 s | 2.559 s | 1.012 s | 7 of 89,484 |
| 9 | site D | no sort, LIMIT 5018, 1 | 923 calls, 1.412 s | 0.105 s | 0.054 s | 1 of 5,574 |
The times are the median of three runs on the scratch copies, a server under its normal load; the slow log's averages
were taken under the production load of the day, with many of the same statements running at once, which is why they
are higher. Row 7 was already fast on the copy (its slow-log times came from waiting on the others). The counts of
the same lists (COUNT(*) instead of COUNT(DISTINCT node_id)) went from 0.78 s to 0.44 s for the whole
share.exponential.earth tree and from 0.62 s to 0.55 s for row 3's list.
What the database does differently: with DISTINCT, EXPLAIN shows Using temporary for these statements; MariaDB
reads every matching row, puts it in a temporary table to remove duplicates, sorts it and then applies the limit.
Without DISTINCT it can read the rows in the order of an index and stop at the limit.
Tests
tests/tests/kernel/classes/eZContentObjectTreeNodeDistinctTest.php: the decision for every query part, without a database.tests/tests/kernel/classes/eZContentObjectTreeNodeDistinctEngineChecks.php, run byeZContentObjectTreeNodeDistinctSqliteTest(SQLite, in process),eZContentObjectTreeNodeDistinctDatabaseTest(MySQL/MariaDB, PostgreSQL, Oracle) andeZContentObjectTreeNodeDistinctMongoDBTest(MongoDB): a fixture of objects in one, two and three languages, with and without the always available flag, two locations for some, a hidden and an invisible node, two owners and sections, an object whose current version is its second; 27 kinds of list in six language settings, each fetched and counted withautoand withalways. Both must give the same node ids, in the same order, with the same counts, no node twice.
References
kernel/classes/ezcontentobjecttreenode.php:nodeListNeedsDistinct(),nodeListDistinctMode(),subTreeByNodeID(),subTreeCountByNodeID(),subTreeMultiPaths(),createSortingSQLStrings(),createAttributeFilterSQLStrings(),createPermissionCheckingSQL()kernel/classes/ezcontentlanguage.php:sqlFilter(),languagesSQLFilter()settings/site.ini:[ContentSettings] NodeListDistinct- MongoDB:
subTreeByNodeID()andsubTreeCountByNodeID()run as aggregation pipelines there and never had DISTINCT;subTreeMultiPaths()goes through the SQL adapter, which reads the query with and without DISTINCT.