AL icon indicating copy to clipboard operation
AL copied to clipboard

The FlowField of a table should be indexed

Open MarcHansenMicrosoft opened this issue 6 years ago • 4 comments

Title The FlowField of a table should be indexed.

Description You can potentially increase performance if fields that are used in FlowFields are added to SumIndexedFields of the corresponding key.

Reason for the rule When there are performance issues on List pages, the root cause is often that they display FlowFields defined on top of tables that are inadequately indexed - these are typically missing SIFT indices. As any FlowField potentially can be shown on a page, make sure that they are all adequately indexed.

Bad code sample

table 18 Customer
{...
    fields
    {...
        field(97; "Debit Amount"; Decimal)
        {
            ...
            CalcFormula = Sum ("Detailed Cust. Ledg. Entry"."Debit Amount" WHERE("Customer No." = FIELD("No."),
                                                                                 "Entry Type" = FILTER(<> Application),
                                                                                 "Initial Entry Global Dim. 1" = FIELD("Global Dimension 1 Filter"),
                                                                                 "Initial Entry Global Dim. 2" = FIELD("Global Dimension 2 Filter"),
                                                                                 "Posting Date" = FIELD("Date Filter"),
                                                                                 "Currency Code" = FIELD("Currency Filter")));
            FieldClass = FlowField;
            ...
        }
        ...
    }
    keys { ... }
    ...
}
table 379 "Detailed Cust. Ledg. Entry"
{...
    fields { ... }
    keys
    {
        key(Key1; "Entry No.")
        {
            Clustered = true;
        }
    }
    ...
}

Good code sample

table 18 Customer
{...
    fields
    {...
        field(97; "Debit Amount"; Decimal)
        {
            ...
            CalcFormula = Sum ("Detailed Cust. Ledg. Entry"."Debit Amount" WHERE("Customer No." = FIELD("No."),
                                                                                 "Entry Type" = FILTER(<> Application),
                                                                                 "Initial Entry Global Dim. 1" = FIELD("Global Dimension 1 Filter"),
                                                                                 "Initial Entry Global Dim. 2" = FIELD("Global Dimension 2 Filter"),
                                                                                 "Posting Date" = FIELD("Date Filter"),
                                                                                 "Currency Code" = FIELD("Currency Filter")));
            FieldClass = FlowField;
            ...
        }
        ...
    }
    keys { ... }
    ...
}
table 379 "Detailed Cust. Ledg. Entry"
{...
    fields { ... }
    keys
    {
        key(Key1; "Entry No.")
        {
            Clustered = true;
        }
        key(Key2; "Customer No.", "Entry Type", "Initial Entry Global Dim. 1", "Initial Entry Global Dim. 2", "Posting Date", "Currency Code")
        {
            SumIndexedFields = "Debit Amount"
        }
    }
    ...
}

Good and bad practices for fixing the rule Investigating the use of SIFT for the table. Maintaining SIFTs is expensive, and if you have a high-traffic table such as Sales Line or Gen. Journal Line, you may want not to add too many SIFTs, as the number of lines rarely would exceed a few thousand, so overall a SELECT SUM() from the table may be OK compared to the overhead of maintaining the SIFT. Sometimes there is already a SIFT, but one amount field is missing from it.

Remarks ​This will likely be added as a info not a warning.

MarcHansenMicrosoft avatar Jan 22 '20 08:01 MarcHansenMicrosoft

This would be great if there was a way to disable the info/warning for a particular FlowField. Because I really like the idea but, if I've reviewed the field and the performance hit of adding the SIFT does not make it worth it, I don't want to be spammed by the compiler constantly, as otherwise I might miss other important warnings, and there is no way to know for sure whether a particular warning has been reviewed or not.

Without this option it could become specially annoying (I'm thinking of one of the already existing warnings) when there is no way for you to do anything about it because fixing it would require a key that included standard and custom fields.

salgiza avatar Jan 23 '20 09:01 salgiza

Thanks for the input

MarcHansenMicrosoft avatar Jan 23 '20 12:01 MarcHansenMicrosoft

I suppose this one would arise for a FlowField in Table Extension that uses both fields of a base table and of a companion table in CalcFields expression. To my knowledge there is yet no official recommendation how to form keys in this case. In this case I would not throw an info especially is developer cannot do anything about it.

miljance avatar Jan 24 '20 12:01 miljance

Thank you for reporting this issue. Unfortunately, we do not find it important enough to address at this point.

mazhelez avatar Jun 21 '22 13:06 mazhelez