To understand why a query is slow, you have to see what it turns into in the DBMS. Every BAS ERP object — a catalog, a document, a register — is stored in ordinary SQL Server tables, and the platform translates your query into SQL over those tables.
Tables and references
Reference objects (catalogs and documents) live in tables such as _Reference and _Document with a numeric suffix, and every record has a 16-byte identifier. A reference to a document is that identifier; links between tables are joins on it. Registers have no references of their own: their records belong to a recorder document.
Virtual tables are queries, not tables
Balance, Turnovers or SliceLast do not exist in the database. The platform builds them on the fly from the register movement table and, for accumulation registers, the totals table. That is why parameters of a virtual table filter data much earlier — and faster — than a WHERE condition placed after it.
Composite types cost extra
A field of a composite type is stored as several columns: the type, the table reference and the values themselves. A query that dereferences such a field joins every possible table. One extra type in a composite field can turn a simple query into a heavy one.
Indexes: what the platform creates and what it does not
The platform creates a clustered index and a few standard ones for every table: by reference, by code and name, by date and number, by register dimensions. Anything else comes only from the “Index” property of an attribute or dimension. That is why a query that filters by an ordinary attribute often reads the whole table: there is simply no index for it, and SQL Server has to scan every row.
To see what your query really turns into, catch its SQL text in the technology log or a SQL Server trace and look at the actual execution plan. Table scans, key lookups and huge row estimates show at once where the time goes.
This is the foundation of the first part of our BAS ERP optimisation course: without the physical structure, neither locks nor query plans make sense.
