#!/usr/bin/env python3 """检查 user_dashou 中有 user_id 的记录""" import re with open('xaio_cheng_xu_backup.sql', 'r', encoding='utf-8') as f: content = f.read() pattern = re.compile(r"INSERT\s+INTO\s+`user_dashou`\s+VALUES\s*\((.+?)\)\s*;", re.IGNORECASE | re.DOTALL) matches = list(pattern.finditer(content)) # 找有 user_id 的记录 has_uid = 0 no_uid = 0 uid_values = [] for m in matches: v = m.group(1).rstrip() if v.endswith('NULL'): no_uid += 1 else: has_uid += 1 # 提取最后一个值(user_id) last_comma = v.rfind(',') uid_val = v[last_comma+1:].strip() uid_values.append(uid_val) print(f"有 user_id: {has_uid}, 无 user_id: {no_uid}") print(f"user_id 值样本: {uid_values[:10]}") # 检查 user_main 中这些 user_id 是否存在 # user_main 的 id 字段是 vals[1] main_pattern = re.compile(r"INSERT\s+INTO\s+`user_main`\s+VALUES\s*\((.+?)\)\s*;", re.IGNORECASE | re.DOTALL) main_ids = set() for m in main_pattern.finditer(content): # 简单提取第二个字段 (id) v = m.group(1) # 找前几个逗号 in_q = False commas = [] for i, ch in enumerate(v): if ch == "'": in_q = not in_q elif ch == ',' and not in_q: commas.append(i) if len(commas) >= 2: break if len(commas) >= 2: id_val = v[commas[0]+1:commas[1]].strip() main_ids.add(id_val) print(f"\nuser_main id 范围: {len(main_ids)} 个") matched = sum(1 for uid in uid_values if uid in main_ids) print(f"user_dashou user_id 匹配 user_main: {matched}/{len(uid_values)}") # 也检查 user_type 分布 type_pattern = re.compile(r"INSERT\s+INTO\s+`user_main`\s+VALUES\s*\((.+?)\)\s*;", re.IGNORECASE | re.DOTALL) type_counts = {} for m in type_pattern.finditer(content): v = m.group(1) # 找第12个字段 (user_type, index 11) in_q = False commas = [] for i, ch in enumerate(v): if ch == "'": in_q = not in_q elif ch == ',' and not in_q: commas.append(i) if len(commas) >= 12: break if len(commas) >= 12: type_val = v[commas[10]+1:commas[11]].strip().strip("'") type_counts[type_val] = type_counts.get(type_val, 0) + 1 print(f"\nuser_type 分布: {type_counts}")