Skip to content

Commit aebadd4

Browse files
tanmoysrtCopilot
authored andcommitted
fix(database): Batch no of tables during analyze table
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> (cherry picked from commit 6fbbcfc)
1 parent 827da77 commit aebadd4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

agent/database_server.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,16 @@ def analyze_tables_of_database(self, private_ip: str, mariadb_root_password: str
193193
if not tables:
194194
return
195195

196-
tables_str = ", ".join([f"`{t}`" for t in tables])
197-
query = f"ANALYZE TABLE {tables_str};"
198-
success, msg = db.execute_query(query)
199-
if not success:
200-
raise Exception(f"Failed to analyze tables for {database}: {msg}")
196+
# Batch tables to avoid exceeding server statement-size limits / max_allowed_packet
197+
batch_size = 100
198+
for start in range(0, len(tables), batch_size):
199+
batch = tables[start : start + batch_size]
200+
tables_str = ", ".join(f"`{t}`" for t in batch)
201+
query = f"ANALYZE TABLE {tables_str};"
202+
success, msg = db.execute_query(query)
203+
if not success:
204+
batch_index = start // batch_size + 1
205+
raise Exception(f"Failed to analyze tables for {database} in batch {batch_index}: {msg}")
201206

202207
@step("Update Database Schema Size")
203208
def update_database_schema_size(

0 commit comments

Comments
 (0)