Skip to main content

Using AI to Optimize Your SQL Code

If enabled for your account, you can use LiveRamp Clean Room's AI features to generate suggested improvements to your SQL code. This can help improve the performance of your queries in the context of distributed in-memory processing via Spark. This can help to reduce the processing time of your Question runs.

The recommendations are displayed in your run report once you run your query. The "Query Plan" shows which parts of your code could be optimized for platform efficiency and technical alignment, such as SQL functions, JOIN operations, resource sizing, and overall query structure.

Note

LiveRamp Clean Room's AI tool bases its recommendations on historical run performance data and code characteristics. It does not use your SQL code as training data.

AI-generated suggestions are intended as guidance, not definitive solutions. LiveRamp has attempted to restrict the advice to supported optimizations. However, AI can make mistakes. The suggestions may not all be supported by LiveRamp Clean Room's Spark implementation.

Procedure. To view a query plan:
  1. On the Questions page, select ReportView Reports for the question.

    View_Reports.png

    The Question Runs page displays the recent question runs.

  2. In the row for the question run that you want to analyze, click View Report.

    Question_Runs_Page-View_Reports_Button.png

    The report run page displays the question's runtime parameters and a table of its results.

  3. Click View Query Plan.

    Report_Run_Page.png

    The Query Plan page summarizes the steps that Spark SQL took to run the question.

  4. In the Optimization Strategies section, click Ask: "How can I optimize this query?".

    Query_Plan-Optimization_Strategies.png

    After analyzing your query, the following sections are displayed:

    • Analysis Summary: A high-level summary of the subsequent sections

    • Performance Bottlenecks: Describes any significant limitations inherent in the logical structure of your query.

    • Optimization Strategy: Describes the proposed strategy, such as structural simplifications.

    • Optimized Query: A code block with a modified version of your query.

    • Implementation Risks: Lists any possible impacts, such as resource utilization.

    Optimization_Strategies.png
  5. Consider the suggestions and copy them if you need to refer back to them. The AI helper will also often provide code to copy and paste in your question builder editor for testing.