Repository navigation
Conversation
… use it Turn off the indexes on the IC Partner Code field of G/L Entry, Customer and Vendor in companies that don't use intercompany (upgrade and company initialization), and queue them to be turned on again when an IC partner is created. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ndexes Filtering G/L Entry, Customer and Vendor on IC Partner Code is expensive on large tables, and an empty IC Partner table is a sufficient signal. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The platform already emits LC0063 and LC0064 when Index Management enables or disables a key. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Company initialization is a critical path. Turning an index off reads Database Index (catalog and DMV queries), takes a tenant lock, runs DDL and invalidates the index override cache, so it now runs in a task scheduled from OnCompanyInitialize in the new codeunit 438 IC Partner Code Indexes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…esn't run Don't register the upgrade tag as a per-company tag, and set it from the background task instead, so that companies where the task couldn't be created or failed are handled by the upgrade code. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ization Remove the OnCompanyInitialize background task and codeunit 438. The upgrade tag isn't registered as a per-company tag, so the upgrade step handles new companies at the next upgrade, while their tables are still small. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…reated EnableKey isn't a no-op for an index that already exists (the maintenance job drops and recreates it), so the Database Index check is needed, but only the first IC partner can find the indexes turned off. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Good Sense Reviewer - Round 1Recommendation: Accept with SuggestionsWhat this PR doesTurns off three IC Partner Code indexes in companies without IC partners during upgrade, then queues them for rebuilding when the first partner is inserted. This reduces unused index maintenance, especially on G/L Entry. The eight upgrade implementations and four upgrade-tag definitions are consistent. Key lookup accounts for localization differences, existing IC companies retain their indexes, and new companies are deliberately handled at their next upgrade. Normal partner insertion restores the indexes, but inserts that skip table triggers bypass that restoration. Problem-solution fitFit: Partial The change targets the intended index overhead without changing financial records or key metadata. Automatic restoration does not cover importing the first IC partner with table triggers skipped. SuggestionsS1 (🟠 Moderate): Re-enable indexes when insert triggers are skipped Risk assessment and necessityRisk: The changed paths affect per-company upgrades and initial IC setup, not amounts, ledger contents, or existing public signatures. Rebuilding is delayed until maintenance, so IC queries can temporarily run without these indexes; trigger-skipping imports can leave that state in place indefinitely. No builds or tests were run for this review. Runtime permissions, upgrade-transaction support, on-premises queue processing, and persistence across later schema syncs remain unverified; none is established here as a defect. Necessity: Companies without IC otherwise keep paying write and storage costs for unused indexes. The three-index scope is focused, and retaining the AL keys lets administrators restore indexes needed by extensions.
|
…serted without table triggers Move the logic from the IC Partner OnInsert trigger to an OnAfterInsertEvent subscriber in IC Partner Change Monitor, so that inserts with RunTrigger = false (for example, configuration package imports) are covered. Also fix the AA0021 variable order warning that failed the builds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Good Sense Reviewer - Round 2Recommendation: AcceptWhat this PR doesTurns off three IC Partner Code indexes during upgrade in companies without IC partners, then queues them for rebuilding when the first partner is inserted. This reduces unused index maintenance, especially on G/L Entry. This update moves restoration from Problem-solution fitFit: Strong The change targets unused index overhead without changing financial records or key metadata. The previous restoration gap for imports that skip table triggers is now closed; newly created companies remain deliberately deferred until their next upgrade. Status of previous suggestions
New observations (commits since round 1)None — the update addresses the previous suggestion and corrects variable ordering. Risk assessment and necessityRisk: The changed paths affect upgrades and initial IC setup, not amounts, ledger contents, or existing public signatures. First-partner imports now queue index work too, and IC queries may scan until maintenance rebuilds the indexes. Ordinary-user permissions, upgrade-transaction support, on-premises queue processing, and persistence across later schema syncs remain unverified; none is established here as a defect. No builds or runtime tests were run for this review. Necessity: Companies without IC otherwise keep paying write and storage costs for unused indexes. The three-index scope is focused, and retaining the AL keys lets administrators restore indexes needed by extensions.
|
What & why
G/L Entry, Customer and Vendor each have a non-unique key on
"IC Partner Code"that only intercompany (IC) code reads. Every company still maintains these indexes, even though most never use IC. G/L Entry is the costly one: it's large and insert-heavy, and the column is almost always empty.This change turns these indexes off at runtime, through the platform's
Index Managementcodeunit, in companies that don't use IC. It turns them back on as soon as a company starts using IC:IC Partner.DisableICPartnerCodeIndexesIfICNotUsed(), guarded by the upgrade tagMS-661822-DisableICPartnerCodeIndexes-20261202. The only check isIC Partner.IsEmpty(); the code deliberately doesn't filter G/L Entry, Customer or Vendor on"IC Partner Code", because that would be expensive on large tables (a full scan if the index is already off). CheckingIC Partneralone is enough: the"IC Partner Code"fields relate toIC Partner, deleting an IC partner clears the code on G/L Entries and is blocked while a customer or vendor is linked, and every code path that reads these indexes starts from an existing IC partner.OnGetPerCompanyUpgradeTags, so company initialization doesn't mark it as done, and the upgrade step handles each new company at the next upgrade. Company initialization is a critical path, and turning an index off isn't cheap: per table it readsDatabase Index(catalog views plussys.dm_db_index_physical_stats), takes a tenant-level app lock (up to 30 s wait), runsDROP INDEX, writes the index state, and invalidates the index-override cache on all server instances. Until the next upgrade, a new company keeps the indexes, but its tables are small then, so the indexes cost little to maintain and are cheap to drop. Companies created with Copy Company inherit the source company's index state (CopyCompanyOverridesin the platform).OnAfterInsertEventsubscriber onIC Partner(in codeunit 489IC Partner Change Monitor) callsIC Partner.EnableICPartnerCodeIndexesIfFirstICPartner(), which callsIndex Management.EnableKeyfor any of the three indexes missing fromDatabase Indexfor the current company. This only queues the index; the platform builds it in the next maintenance window. Later IC partners skip this with oneIsEmptyon the other partners, because the indexes are then already on or queued. TheDatabase Indexcheck itself is needed:EnableKeyisn't a no-op for an index that already exists, because the maintenance job (EnableSingleIndexAsync) drops and recreates it. A table event is used instead of theOnInserttrigger so that inserts that skip table triggers, such as configuration package imports with Skip Table Triggers, also turn the indexes back on.Every company that takes part in IC, on the sending or receiving side, must have an
IC Partnerrecord for the other company. Database delivery fails withICPartnerMissingCurrentCompanyErrwithout it, and accepting inbox documents callsICPartner.Get. So inserting an IC partner reliably signals that a company uses IC.Implementation notes:
Key8in W1 butKey9in BE and FI). The code finds the single-field, non-unique BaseApp key on"IC Partner Code"usingRecordRef/KeyRef.Enabled = falsein the metadata, so admins can still turn these indexes on or off from Table Information, and the schema doesn't change.[TryFunction]. The upgrade step and theIC Partnerinsert run in write transactions, so the calls are direct. Each call is guarded by a check that the key exists and that the index isn't already in the target state.IC Partnertable gets an indirect read onDatabase Index, as the System Application's Table Information pages have.LC0063(index enabled at runtime) andLC0064(index disabled at runtime) forIndex Managementcalls.UpgradeBaseApp(AT, BE, CH, IT, NL, NO, RU) andUpgradeTagDefinitions(BE, IT, RU) files.Reviewers from Server Runtime, please confirm:
IndexManagement.DisableKeycan be called inside the per-company upgrade transaction, and the tenant-level app lock it takes (up to 30 s wait) is acceptable there.ApplyIndexOverrideStateinCreateNonSiftIndexesseems to ensure this.Database Index(Getwith the name fromGetKeyIndexName, plusEnabled) is the right way to tell whether an index currently exists for a company.TryGetByPrimaryKeyalso runssys.dm_db_index_physical_statsto fill in Fragmentation. Is there a cheaper way from AL to read the runtime enabled state?Key.Enabledonly returns the metadata value.Linked work
Fixes AB#661822
How I validated this
What I tested and the outcome (required — be specific: scenarios, commands, screenshots for UI changes)
al_buildfor W1 BaseApp: failed because of errors already in my local workspace (missing DotNet references and outdated System symbols, for exampleUri.IsHttpUrl). None of the errors are in the changed files. CI will do the full compile, including the country layers.Insert(false), and a user who isn't an admin can still create an IC partner.Database Index, which reads SQL Server's index metadata, and on the nightly maintenance run, so the result can't be checked in a unit test.SetCurrentKey("IC Partner Code")only adds anORDER BY, so IC code works the same while an index is off.Risk & compatibility
IsEmptyonIC Partner), and it's guarded by an upgrade tag."IC Partner Code"without an index. That affects posting IC documents, the IC Transactions report and deleting an IC partner.Database Index(granted indirectly by the table) and callsIndex Management.EnableKey.LC0063andLC0064to monitor which indexes are turned on and off.