The application relates to the technical field of
data optimization, and discloses a
SQL optimization method based on dynamic statistical feature
perception, equipment and a medium. The method comprises the following steps: identifying and analyzing a to-be-optimized
SQL, and extracting table fields in filtering, association, grouping or sorting conditions as predicate columns; calculating the selectivity of each predicate column, and determining a predicate column with selectivity lower than a threshold value or a single value proportion exceeding a preset proportion as a key column; extracting column-level statistical information including
histogram boundary values, null value proportions, different value quantities and the frequency of the most common values for the key column, and converting the column-level statistical information into a
natural language statistical summary through a statistical
feature descriptor; constructing a prompt word
context based on an original
SQL statement, table structure information of the key column and the summary, and inputting a large
language model to generate a candidate SQL. According to the application, key columns are dynamically screened, and a
natural language description of data distribution
perception is generated, so that the consumption of Token input of the large
language model is reduced, irrelevant information interference is avoided, and the SQL optimization precision is improved.