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.
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.1asrequest_method.If you cannot modify the column name, use an alias to provide additional information.
For example, an indexed field is named
testbut it records the request status. In this case, you can enterstatusas 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_nameas the indexed field name instead offileor 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
to open the Copilot interface. Select SQL Generation, Explanation, or Diagnosis as needed.
Examples of generating SQL statements
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 thebody_bytes_sentfield for the total.
Further analyze a specific
hostand calculate a percentile: Analyze the P95 percentile of the data volume forservice.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.
Traffic varies among
hosts. Calculate the difference in request volume between the hosts with the most and fewest requests: Query for thehostwith the maximum request volume and thehostwith 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.NoteFor 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.
Enter the query requirement.

The result displays the difference, but not the maximum or minimum values of
host.Refine the query to also show the
hosts with the maximum and minimum traffic.
After using it, Copilot correctly analyzed our requirements.
Examples of explaining SQL statements
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.

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

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

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.



