Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,220 of 9,220 pages
About the help in other languages
All help pages

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…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/guides/content-node-lists.md

On this page

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 DISTINCT only 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 uses COUNT(*) instead of COUNT(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=always in settings/override/site.ini.append.php restores 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:

TableJoined onRows per node
ezcontentobject_treethe list's own rows, one per node1
ezcontentobjectid = ezcontentobject_tree.contentobject_id (primary key)1
ezcontentclassid = ezcontentobject.contentclass_id AND version = 0 (primary key id, version)1
ezcontentobject_namethe 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:

ParameterWhat it joins
SortBy attributeezcontentobject_attribute (and the datatype's own table for a custom sort)
SortBy class_nameezcontentclass_name
SortBy stateezcobj_state, ezcobj_state_link
AttributeFilter on an attribute or class_nameezcontentobject_attribute, ezcontentclass_name
ExtendedAttributeFilter (any: its tables, joins, columns or GROUP BY)whatever the filter's handler adds (eZ Tags, relations, keywords)
GroupBythe GROUP BY of the list
a Group limitation in the user's read policiesa temporary table of the owners in the user's groups
a StateGroup limitation in the user's read policiesezcobj_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, ClassFilterType and ClassFilterArray, ObjectNameFilter, Language and the site's language list;
  • SortBy on path, path_string, published, modified, modified_subnode, section, node_id, contentobject_id, depth, class_identifier, priority, visibility, name;
  • AttributeFilter on node and object columns: modified_subnode, published, modified, section, depth, priority, owner, visibility, name, path, node_id, contentobject_id, class_identifier, and state (a sub-select in the WHERE clause);
  • 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
ValueEffect
auto (default; also when the setting is missing)DISTINCT and COUNT(DISTINCT node_id) only for the query shapes listed under What keeps DISTINCT
alwaysDISTINCT 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 list

php 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.

#SiteListSlow log: calls, averageBefore (DISTINCT)AfterRows read
1share.exponential.earthforum topic, previous: modified_subnode < X, ORDER BY modified_subnode DESC, node_id, LIMIT 113,479 calls, 1.894 s0.163 s0.002 s1 of 1,649
2share.exponential.earthforum topic, next: modified_subnode > X, ascending, LIMIT 19,491 calls, 1.841 s0.340 s0.001 s1 of 4,450
3site Bclass 38 below /1/2/, ORDER BY published DESC LIMIT 46145, 3002,764 calls, 2.132 s1.799 s1.087 s300 of 56,758
4site CORDER BY published DESC LIMIT 4038, 11,501 calls, 1.504 s0.099 s0.039 s1 of 4,338
5share.exponential.earthwhole tree by path, LIMIT 0, 49000 (sitemap)626 calls, 2.988 s2.584 s1.053 s49,000 of 70,358
6share.exponential.earthsubTreeMultiPaths(), ORDER BY published DESC LIMIT 30460 calls, 3.874 s3.153 s1.566 s30 of 89,285
7site DORDER BY priority DESC LIMIT 17692 calls, 2.173 s0.002 s0.002 s17 of 27
8share.exponential.earthORDER BY modified DESC, a few rows361 calls, 3.649 s2.559 s1.012 s7 of 89,484
9site Dno sort, LIMIT 5018, 1923 calls, 1.412 s0.105 s0.054 s1 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 by eZContentObjectTreeNodeDistinctSqliteTest (SQLite, in process), eZContentObjectTreeNodeDistinctDatabaseTest (MySQL/MariaDB, PostgreSQL, Oracle) and eZContentObjectTreeNodeDistinctMongoDBTest (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 with auto and with always. 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() and subTreeCountByNodeID() run as aggregation pipelines there and never had DISTINCT; subTreeMultiPaths() goes through the SQL adapter, which reads the query with and without DISTINCT.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x