MSBA-348 · Lesson 7 of 12 · 17 min

Domain review: security and performance

▶ Video coming soon A video version of this lesson is on the way.

The last domain, Implement security and optimize performance, carries 10 to 15 percent. It has three objective groups: implement security policies and requirements; apply fundamental performance optimization techniques; and optimize performance. The change log rates the fundamental techniques as a major change, because the new outline names global cache and singleton, temporary tables and set-based versus row-based queries as explicit skills. This lesson reviews the domain through the work in Security, Performance and ALM for Finance and Operations, where Desmond and Prudence split the warranty privileges, built Cobalt Ridge's one extensible data security policy and cut a purchase receipt from 236 seconds to 31.

The role-based security model

Security in finance and operations is built in layers. A permission is access to a securable object at a level: Read, Update, Create, Delete, or Invoke for action items and service operations. A privilege groups the permissions needed for one task, usually by pointing at one or more entry points (menu items, service operations, data entity OData endpoints) with an access level. A duty groups privileges for a part of a business process. A role groups duties and privileges for a job and is what users are assigned. Developers create privileges, duties and roles in Visual Studio, or extend standard ones with role and duty extensions; security administrators can also create them in the Security configuration page, but production security should be source-controlled.

A layered diagram. At the bottom, entry points: a display menu item, an output menu item and an action menu item. Above them, privileges such as CRPumpWarrantyTableView with Read and CRPumpWarrantyVoid with Invoke. Above those, duties such as CR Inquire pump warranties and CR Void pump warranties. At the top, roles such as Service desk agent and CR Warranty void. To the side, an extensible data security policy filters rows of CRPumpWarrantyTable for one role.
Role-based security grants access to entry points; extensible data security filters which rows a role can see.

Two further mechanisms control access below the menu item. The table permissions framework (a table property) makes the platform enforce table access on server-side code paths and services, not only through the form. Form control permissions let a privilege grant or deny access to a specific control or field on a form. The exam might describe a requirement such as "the cost field must be read-only for clerks" and expect a form control or field-level permission on a privilege, not a custom check in code.

Segregation of duties rules name two duties that should not be held by the same user. When a role assignment would break a rule, the system logs a conflict for a security administrator to resolve or accept. At Cobalt Ridge there were two such rules: maintaining warranties versus voiding them, and requesting an inspection waiver versus approving it.

Security policies and extensible data security

The outline lists two separate skills: implement security policies and implement Extensible Data Security (XDS) policies. In practice, security policies in finance and operations are XDS policies; the first skill is the general one (design a policy that meets a requirement) and the second is the mechanics.

An XDS policy has a primary table, a policy query that selects the allowed rows of the primary table, a context that decides when the policy applies (a role name, a role property or an application context set in code), and one or more constrained tables whose rows are filtered through a relation to the primary table. Cobalt Ridge's CRMiningWarrantyPolicy used CustTable as the primary table, a query selecting customers in the MINING group, a role-name context on the CR Mining service coordinator role, and CRPumpWarrantyTable and CustTrans as constrained tables. A user with that role sees only Mining customers' warranties and transactions everywhere: in forms, reports, entities and services.

The parts of an extensible data security policy.
Policy partQuestion it answersCobalt Ridge value
Primary tableWhich table defines the allowed set?CustTable
Policy queryWhich rows of it are allowed?CustGroup equals MINING
ContextFor whom does the policy apply?Role name: CR Mining service coordinator
Constrained tablesWhich other tables are filtered by the allowed set?CRPumpWarrantyTable, CustTrans
OperationWhich operations are restricted?Select (read) and others as configured per constrained table

XDS facts the exam likes: policies apply to every path that reads the table through the platform, including OData and reports; users who must see everything, such as auditors, are exempted through a role designed to bypass data access policies rather than by editing the policy; when several policies apply to one table, a user sees the intersection of what they allow; XDS is not the tool for financial dimension security; and policies add joins to queries, so a careless policy can slow every query on a busy table. That last point bridges to the performance half of the domain.

Caching

The fundamental techniques start with caching mechanisms for tables and forms. A table's CacheLookup property decides how records are cached on the server.

CacheLookup values. Record caching needs a unique index and a select on all its fields with equality.
CacheLookup valueWhat is cachedSuits
NoneNothingTables updated constantly, such as transaction queues
NotInTTSFound records, but reads inside a transaction go to the databaseTransaction data read often outside transactions
FoundRecords that were foundMain tables read often by key, such as customers
FoundAndEmptyFound records and the fact that a key was not foundLookups where misses are common and costly
EntireTableThe whole table for a companySmall, rarely changed parameter and group tables

Record caching only helps when the select statement uses equality on all fields of a unique index, typically the primary key, and returns a single record; other selects bypass the record cache. EntireTable caching is wrong for large tables or tables that change often, because every change invalidates the whole cached table. Display and edit methods on forms can be cached with the SysClientCacheDataMethod attribute or by registering them with cacheAddMethod, so they are calculated once per row instead of on every repaint.

Global cache and singleton is the new explicit skill. SysGlobalObjectCache is a cache shared across sessions on the same server instance, keyed by scope and key, suited to expensive lookups such as configuration maps; values must be invalidated when the underlying data changes. SysGlobalCache is scoped to a session. A singleton is a class that returns one shared instance, usually through a static instance method that checks a cache before constructing. In the hardening clinics, Desmond stored the casting category map in SysGlobalObjectCache keyed by company, which removed thousands of repeated reads per receipt.

Temporary tables

Temporary tables for optimization come in two kinds. An InMemory table lives in the server's memory, is fast for small data and cannot be joined with database tables in SQL. A TempDB table lives in SQL Server's tempdb database, can be joined with regular tables, and suits large sets and set-based operations; report data providers usually use TempDB tables. The exam often asks which type to use when the code must join the temporary data to a regular table: TempDB.

Set-based versus row-based

The outline asks you to assess when to use set-based or row-based queries. A row-based loop selects and updates records one at a time, sending a round trip per row. A set-based statement, such as insert_recordset, update_recordset or delete_from, sends one statement to the database. RecordInsertList sits between them, buffering inserts into batches.

A set-based insert from the hardening clinics. One statement replaces a loop of row-by-row inserts.
CRInspAlertQueue alert;
PurchLine        line;
CRInspectionCertTable cert;

// Queue an alert for every casting line on the order that has no certificate yet
insert_recordset alert (PurchId, LineNumber, ItemId)
    select PurchId, LineNumber, ItemId from line
        where line.PurchId == purchId
           && line.CRInspectionRequired == NoYes::Yes
        notexists join cert
            where cert.PurchId    == line.PurchId
               && cert.LineNumber == line.LineNumber;

Set-based operations silently fall back to row-by-row when the target table has an overridden insert, update or delete method, when database logging or alerts are configured on the table, when it has data event handlers for those operations, or in some cases with delete actions. The skip methods (skipDataMethods, skipDatabaseLog, skipEvents and skipDeleteActions for delete_from) tell the platform to ignore those reasons, which is correct only when the skipped logic genuinely does not need to run. In the hardening clinics, the alert queue's onInserted handler and an accidental database log both forced fallback; removing the handler and switching off the log, with Thandeka's agreement, made the insert set-based again.

Row-based code is still right when each row needs logic that cannot be expressed in SQL, such as calling a service, or when the volume is tiny. The exam's typical question shows a loop over thousands of rows and asks for the most efficient replacement, with one option that uses a set-based statement on a table with an overridden method, which would fall back.

Query and index optimization

Modify queries to optimize performance covers selecting only needed fields (field lists), using firstonly when you need one row, using exists joins instead of nested loops, filtering on indexed fields, avoiding selects inside loops, and using the right join type. Create and modify indexes for tables and views covers adding an index whose leading columns match the most selective filter, making indexes unique where the data is unique, and not over-indexing tables with heavy inserts. The receipt fix at Cobalt Ridge began with a missing index: CRPurchLineIdx on PurchId and LineNumber turned a scan of the certificate table into a seek.

Index hints are possible in X++ but are rarely the right answer, because they freeze a plan that the optimizer would otherwise adapt. Desmond tried one during the hardening clinics, measured no gain and removed it.

Traces, async and sandbox

Capture and analyze traces with Trace Parser. A user with the right role starts a trace from the client, reproduces the slow action and stops the trace; the trace file is downloaded and opened in Trace Parser on a developer machine. Trace Parser shows a timeline, a call tree with inclusive and exclusive time per method, the X++ methods with the most time, and the SQL statements with their duration and count. The usual finding is either one slow statement (fix the index or query) or one fast statement called thousands of times (fix the loop, cache or go set-based). In the receipt case, isSatisfied took 171 of the 236 seconds because it ran a query per line.

Optimize performance for data entities, data source queries and reports: for entities, enable set-based processing for imports when the entity's logic allows it, avoid virtual fields that run X++ per row on large exports, and limit data sources; for form data sources, avoid display methods that query per row and use joins instead; for reports, do the work in a TempDB table with set-based inserts and use preprocessing for long reports.

Implement Async and Sandbox frameworks. Long operations started from a form block the user's browser session if they run synchronously. The asynchronous options let an operation run while the user continues, for example a SysOperation controller in asynchronous mode or the platform's asynchronous call patterns, and the sandbox option, SysOperationSandbox, runs a static method in a separate session while the form shows progress and stays responsive. The exam is likely to describe a form that freezes for a minute after a button click and ask which approach keeps the client responsive without moving the work to batch.

A horizontal bar chart of the receipt case. Before: total 236 seconds, split into isSatisfied 171, alert queue 38, standard 27. After: total 31 seconds against a target of 45 seconds. Labels show the fixes: index CRPurchLineIdx, header read once, category map in the global object cache, insert_recordset with notexists join.
The receipt case from the hardening clinics. Most of the time was in one method that queried per line.

Security and performance scenarios

Security questions often describe a person and ask for the smallest change. "A warehouse clerk must be able to view warranties but not void them" is a privilege with Read on the display menu item, in a duty added to the clerk's role, and nothing on the action item. "Two field coordinators may see only Mining customers" is an XDS policy. "The person who requests a waiver must not approve it" is a segregation of duties rule. "A service must be callable only by the distributor portal" is a dedicated Microsoft Entra application mapped to a user with a role that grants the service operation. In every case, the wrong answers include a broader role than needed, such as System administrator, or code that checks the user's name.

Performance questions describe a symptom and a measurement. "A list page takes eight seconds to open, and Trace Parser shows a display method calling a query for every row" points to caching the display method or replacing it with a join. "A nightly job inserts two hundred thousand rows one at a time" points to insert_recordset or RecordInsertList. "Every lookup on a parameter table hits the database" points to EntireTable or Found caching. "A button freezes the form for a minute" points to an asynchronous or sandboxed call, or to batch if the user does not need to wait.

Desmond insisted on one habit from the hardening clinics: measure before and after. In the receipt case, the first idea, an index hint, made no measurable difference and was removed. The exam rewards the same discipline: when an option says "capture a trace" or "measure with Trace Parser" as the first step in an investigation, it is usually right, and options that jump straight to a fix without evidence are usually distractors.

Common mistakes

  • MistakeGranting a privilege on a table to secure a form.

    InsteadPrivileges point at entry points such as menu items; tables are protected through those and the table permissions framework.

  • MistakeUsing XDS to restrict financial dimension values.

    InsteadXDS filters rows of tables; dimension security is handled differently.

  • MistakeSetting EntireTable caching on a large transaction table.

    InsteadEntireTable suits small, rarely changed tables; transaction tables use NotInTTS or None.

  • MistakeChoosing an InMemory table that must be joined with a regular table in SQL.

    InsteadUse a TempDB table for joins and large sets.

  • MistakeAssuming update_recordset is always set-based.

    InsteadOverridden methods, logging, alerts or event handlers can make it fall back to row-by-row.

Summary and key terms

  • Security layers: permissions on entry points, grouped into privileges, duties and roles; table permissions and form control permissions go further; segregation of duties rules flag conflicts.
  • XDS policies have a primary table, a policy query, a context and constrained tables; they apply on every path and intersect when several apply.
  • Caching: CacheLookup values, record-cache rules, cached display methods, SysGlobalObjectCache and singletons.
  • TempDB tables can be joined and suit large sets; InMemory tables suit small data.
  • Set-based statements fall back to row-by-row for overridden methods, logging, alerts and handlers; skip methods override that deliberately.
  • Trace Parser finds slow statements and repeated calls; Async and Sandbox frameworks keep the browser responsive.
Privilege
A set of permissions on entry points needed for one task.
Extensible data security
Policies that filter table rows by a query on a primary table for a given context.
CacheLookup
The table property that sets how records are cached.
SysGlobalObjectCache
A cache shared across sessions on one server instance.
TempDB table
A temporary table in SQL Server's tempdb that can be joined with regular tables.
Trace Parser
A tool that examines traces of X++ calls and SQL statements.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Which CacheLookup value caches misses as well as hits?

    Show answer

    FoundAndEmpty.

  2. What does a user see when two XDS policies apply to one table?

    Show answer

    The intersection of the rows both allow.

  3. Name two causes of set-based fallback.

    Show answer

    An overridden insert, update or delete method; database logging; alerts; data event handlers.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz