mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-02-18 02:51:58 -05:00
## Description
---
A `mysql-list-tables-missing-index` tool searches tables that do not
have primary or unique indices in a MySQL database. It's compatible
with:
- cloud-sql-mysql
- mysql
`mysql-list-tables-missing-index` outputs table names, including
`table_schema` and `table_name` in JSON format. It takes 2 optional
input parameters:
- `table_schema` (optional): Only check tables in this specific
schema/database. Search all visible tables in all visible databases if
not specified.
- `limit` (optional): max number of queries to return, default `50`.
## Example
```yaml
tools:
list_tables_missing_index:
kind: mysql-list-tables-missing-index
source: my-mysql-instance
description: Find tables that do not have primary or unique key constraint. A primary key or unique key is the only mechanism that guaranttes a row is unique. Without them, the database-level protection against data integrity issues will be missing.
```
The response is a json array with the following fields:
```json
{
"table_schema": "the schema/database this table belongs to",
"table_name": "name of the table",
}
```
## Reference
| **field** | **type** | **required** | **description** |
|-------------|:------------------------------------------:|:------------:|--------------------------------------------------------------------------------------------------|
| kind | string | true | Must be "mysql-list-active-queries". |
| source | string | true | Name of the source the SQL should execute on.
|
| description | string | true | Description of the tool that is passed
to the LLM. |
## PR Checklist
---
> Thank you for opening a Pull Request! Before submitting your PR, there
are a
> few things you can do to make sure it goes smoothly:
- [x] Make sure you reviewed
[CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [x] Make sure to open an issue as a
[bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose)
before writing your code! That way we can discuss the change, evaluate
designs, and agree on the general idea
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
- [x] Make sure to add `!` if this involve a breaking change
---------
Co-authored-by: Averi Kitsch <akitsch@google.com>
66 lines
3.4 KiB
YAML
66 lines
3.4 KiB
YAML
# Copyright 2025 Google LLC
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
sources:
|
|
cloud-sql-mysql-source:
|
|
kind: cloud-sql-mysql
|
|
project: ${CLOUD_SQL_MYSQL_PROJECT}
|
|
region: ${CLOUD_SQL_MYSQL_REGION}
|
|
instance: ${CLOUD_SQL_MYSQL_INSTANCE}
|
|
database: ${CLOUD_SQL_MYSQL_DATABASE}
|
|
user: ${CLOUD_SQL_MYSQL_USER}
|
|
password: ${CLOUD_SQL_MYSQL_PASSWORD}
|
|
ipType: ${CLOUD_SQL_MYSQL_IP_TYPE:PUBLIC}
|
|
tools:
|
|
execute_sql:
|
|
kind: mysql-execute-sql
|
|
source: cloud-sql-mysql-source
|
|
description: Use this tool to execute SQL.
|
|
list_active_queries:
|
|
kind: mysql-list-active-queries
|
|
source: cloud-sql-mysql-source
|
|
description: Lists top N (default 10) ongoing queries from processlist and innodb_trx, ordered by execution time in descending order. Returns detailed information of those queries in json format, including process id, query, transaction duration, transaction wait duration, process time, transaction state, process state, username with host, transaction rows locked, transaction rows modified, and db schema.
|
|
get_query_plan:
|
|
kind: mysql-sql
|
|
source: cloud-sql-mysql-source
|
|
description: "Provide information about how MySQL executes a SQL statement. Common use cases include: 1) analyze query plan to improve its performance, and 2) determine effectiveness of existing indexes and evalueate new ones."
|
|
statement: |
|
|
EXPLAIN FORMAT=JSON {{.sql_statement}};
|
|
templateParameters:
|
|
- name: sql_statement
|
|
type: string
|
|
description: "the SQL statement to explain"
|
|
required: true
|
|
list_tables:
|
|
kind: mysql-list-tables
|
|
source: cloud-sql-mysql-source
|
|
description: "Lists detailed schema information (object type, columns, constraints, indexes, triggers, comment) as JSON for user-created tables (ordinary or partitioned). Filters by a comma-separated list of names. If names are omitted, lists all tables in user schemas."
|
|
list_tables_missing_unique_indexes:
|
|
kind: mysql-list-tables-missing-unique-indexes
|
|
source: cloud-sql-mysql-source
|
|
description: "Find tables that do not have primary or unique key constraint. A primary key or unique key is the only mechanism that guaranttes a row is unique. Without them, the database-level protection against data integrity issues will be missing."
|
|
list_table_fragmentation:
|
|
kind: mysql-list-table-fragmentation
|
|
source: cloud-sql-mysql-source
|
|
description: List table fragmentation in MySQL, by calculating the size of the data and index files and free space allocated to each table. The query calculates fragmentation percentage which represents the proportion of free space relative to the total data and index size. Storage can be reclaimed for tables with high fragmentation using OPTIMIZE TABLE.
|
|
|
|
toolsets:
|
|
cloud_sql_mysql_database_tools:
|
|
- execute_sql
|
|
- list_tables
|
|
- get_query_plan
|
|
- list_active_queries
|
|
- list_tables_missing_unique_indexes
|
|
- list_table_fragmentation
|