Home Discussions Questions & Answers Using Anchors to Eliminate Non-Performant NVL Logic

Using Anchors to Eliminate Non-Performant NVL Logic

Avatar photoCustomer December 11, 2023 at 5:55 pm

We need to handle optional parameters efficiently. Why is using anchors preferred over the common pattern column_name=nvl(:bind_variable, column_name)?

Viewing 4 reply threads
  • Author
    Replies
    • Support December 13, 2023 at 8:49 pm  

      The nvl pattern is a frequent source of non-performant SQL because it often prevents index usage. Blitz Report avoids this by creating dynamic SQL at run-time.

    • Avatar photoCustomer December 14, 2023 at 10:27 pm  

      How do anchors specifically help optimize the query?

    • Support December 15, 2023 at 5:06 am  

      Anchors (like 1=1 or &lexical) act as placeholders. If the user does *not* enter a value for an optional parameter, the corresponding SQL clause is dropped entirely from the query, resulting in a cleaner and faster execution plan.

    • Avatar photoCustomer December 15, 2023 at 8:23 am  

      If I use a bind variable directly (:bind), does it also get optimized this way?

    • Support December 17, 2023 at 1:04 am  

      No, if you use a standard bind variable (:bind), you lose the ability to dynamically drop the clause, which is why using anchors is recommended for optional parameters that need dynamic insertion.

Viewing 4 reply threads
  • You must be logged in to reply to this post.

Login with: