Generate query and analysis statements with AI (Copilot)

更新时间:
复制 MD 格式

Simple Log Service Copilot lets you use natural language to create SQL statements, analyze log content or SQL statements, and enhance query efficiency.

Prerequisites

You have created indexes. If you want to analyze logs, you need to create field indexes and enable statistics.

Important

For Copilot to accurately understand and generate SQL, make sure your index design and field names meet the following conditions:

  • Define clear and semantically explicit index column names.

    For example, define the index name for GET /HTTP/1.1 as request_method.

  • If you cannot modify the column name, use an alias to provide additional information.

    For example, an indexed field is named test but it records the request status. In this case, you can enter status as the index alias for clarity.

  • Avoid using field names that are similar in meaning or ambiguous.

    For example, if an index records a file name, use file_name as the indexed field name instead of file or other names.

Limits

Currently, Copilot only applies to SQL statements, not SPL statements.

Feature overview

  • Generate SQL statements: You can express your query requirements in natural language. Copilot automatically converts your descriptions into accurate SQL query statements, which significantly reduces the complexity of writing queries.

  • Explain SQL statements: Analyzes SQL statements to explain their structure and function. This helps you better understand query logic and improve your SQL skills.

  • Optimize SQL statements: Analyzes SQL performance and structure to identify potential optimizations and provides specific suggestions to improve query efficiency.

Procedure

Log on to the Simple Log Service console. On the query and analysis page for the target Logstore in your project, click image to open the Copilot interface. Select SQL Generation, Explanation, or Diagnosis as needed.

Examples of generating SQL statements

Important

To improve the accuracy of Copilot recognition, we recommend using clear expressions, such as "Query...", "Analyze...", "Write an SQL..." etc.

  • Count a field: Analyze the total number of requests for different hosts. Use the body_bytes_sent field for the total.

    image

  • Further analyze a specific host and calculate a percentile: Analyze the P95 percentile of the data volume for service.cn-shanghai.log.aliyun-inc.com. Because percentile is not a standard SQL function, Copilot must recognize the intent and use the appropriate Simple Log Service function.

    image

  • Traffic varies among hosts. Calculate the difference in request volume between the hosts with the most and fewest requests: Query for the host with the maximum request volume and the host with the minimum request volume.

    The challenge is that a single SQL statement must identify the hosts with the maximum and minimum traffic and then calculate the difference between them.

    Note

    For complex SQL with multiple conditions, Copilot may encounter syntax errors or no data issues. We recommend using a step-by-step consultation approach to gradually refine the SQL. For example, in this example, first calculate the quantities of the hosts with the maximum and minimum request volumes, and then calculate the difference between the two.

    1. Enter the query requirement.

      image

    2. The result displays the difference, but not the maximum or minimum values of host.

    3. Refine the query to also show the hosts with the maximum and minimum traffic.

      image

    4. After using it, Copilot correctly analyzed our requirements.

Examples of explaining SQL statements

Important

To improve the accuracy of Copilot recognition, we recommend using clear expressions, such as "Analyze...", "Explain...", etc.

  • Explain complex SQL

    Input complex SQL, and Copilot will tell you the meaning of the SQL statement and the meaning of each field.

    image

  • Query SQL functions

    Simple Log Service includes many SQL functions, and Copilot can provide explanations and examples of functions based on descriptions.

    image

  • Query field information

    Simple Log Service interprets the fields in raw logs to help you understand the log content.image

Examples of optimizing SQL statements

Through intelligent analysis of SQL performance and structure, identify potential optimization points and provide specific improvement suggestions, aiming to ensure that queries can be executed efficiently.

image