"""确认 pms_dev 上 charge_records 的索引(含能耗报表新增的两条)。""" import pymysql conn = pymysql.connect(host="10.8.0.252", user="root", password="Hbhyg731024@", database="pms_dev") cur = conn.cursor() cur.execute( "SELECT index_name, GROUP_CONCAT(column_name ORDER BY seq_in_index) AS cols, " "non_unique FROM information_schema.statistics " "WHERE table_schema = 'pms_dev' AND table_name = 'charge_records' " "GROUP BY index_name, non_unique ORDER BY index_name" ) print("charge_records 索引:") for name, cols, non_unique in cur.fetchall(): kind = "UNIQUE" if non_unique == 0 else "INDEX" print(f" {kind:6} {name:40} ({cols})") cur.execute( "SELECT COUNT(*) FROM information_schema.statistics " "WHERE table_schema='pms_dev' AND table_name='charge_records' " "AND index_name='idx_charge_records_cabinet_start_time'" ) print("idx_charge_records_cabinet_start_time 存在:", cur.fetchone()[0] == 2, "(2 列)") cur.execute( "SELECT COUNT(*) FROM information_schema.statistics " "WHERE table_schema='pms_dev' AND table_name='charge_records' " "AND index_name='idx_charge_records_start_time'" ) print("idx_charge_records_start_time 存在:", cur.fetchone()[0] == 1, "(1 列)") cur.close() conn.close()