Skip to content

增加判断row['rows']为整型 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: sql_helper_1.1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions src/sql_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@
add_index_fields = []
# 判断是否需要加索引的条件
# 2023-08-22日更新:修复join多表关联后,where条件表达式字段判断不全。
if (len(join_fields) != 0 and ((row['type'] == 'ALL' and row['key'] is None) or int(row['rows']) >= 1)) or (len(join_fields) == 0 and ((row['type'] == 'ALL' and row['key'] is None) or int(row['rows']) >= 1000)):
if (row['type'] == 'ALL' and row['key'] is None) or (
isinstance(row['rows'], int)
and row['rows'] >= (1 if len(join_fields) != 0 else 1000)
):
# 判断表是否有别名,没有别名的情况:
if has_table_alias(table_aliases) is False and contains_dot is False:
if len(where_fields) != 0:
Expand Down Expand Up @@ -211,10 +214,7 @@
index_columns = add_index_fields[0]
index_result = check_index_exist(mysql_settings, table_name=table_name, index_column=index_columns)
if not index_result:
if row['key'] is None:
print(
f"\033[93m建议添加索引:ALTER TABLE {table_name} ADD INDEX idx_{index_name}({index_columns});\033[0m")
elif row['key'] is not None and row['rows'] >= 1:
if row['key'] is None or (isinstance(row['rows'],int) and row['rows'] >= 1):
print(
f"\033[93m建议添加索引:ALTER TABLE {table_name} ADD INDEX idx_{index_name}({index_columns});\033[0m")
else:
Expand All @@ -231,10 +231,7 @@
table_name=table_name, index_columns=merged_columns,
index_number=len(add_index_fields))
if index_result_list is None:
if row['key'] is None:
print(
f"\033[93m建议添加索引:ALTER TABLE {table_name} ADD INDEX idx_{merged_name}({merged_columns});\033[0m")
elif row['key'] is not None and row['rows'] >= 1:
if row['key'] is None or (isinstance(row['rows'],int) and row['rows'] >= 1):
print(
f"\033[93m建议添加索引:ALTER TABLE {table_name} ADD INDEX idx_{merged_name}({merged_columns});\033[0m")
else:
Expand Down Expand Up @@ -328,10 +325,7 @@
index_columns = add_index_fields[0]
index_result = check_index_exist(mysql_settings, table_name=table_real_name, index_column=index_columns)
if not index_result:
if row['key'] is None:
print(
f"\033[93m建议添加索引:ALTER TABLE {table_real_name} ADD INDEX idx_{index_name}({index_columns});\033[0m")
elif row['key'] is not None and row['rows'] >= 1:
if row['key'] is None or (isinstance(row['rows'],int) and row['rows'] >= 1):
print(
f"\033[93m建议添加索引:ALTER TABLE {table_real_name} ADD INDEX idx_{index_name}({index_columns});\033[0m")
else:
Expand All @@ -348,10 +342,7 @@
table_name=table_real_name, index_columns=merged_columns,
index_number=len(add_index_fields))
if index_result_list is None:
if row['key'] is None:
print(
f"\033[93m建议添加索引:ALTER TABLE {table_real_name} ADD INDEX idx_{merged_name}({merged_columns});\033[0m")
elif row['key'] is not None and row['rows'] >= 1:
if row['key'] is None or (isinstance(row['rows'],int) and row['rows'] >= 1):
print(
f"\033[93m建议添加索引:ALTER TABLE {table_real_name} ADD INDEX idx_{merged_name}({merged_columns});\033[0m")
else:
Expand Down