我发现在CREATE TABLE IF NOT EXIST xxx_table 这样的SQL执行会导致字段解析乱序;我分析到代码如果已经存在的表,执行这样的SQL会更新table cache schema,是不是这样原因导致的?
if (!isSeek && !isDml) { // 使用新的表结构元数据管理方式 EntryPosition position = createPosition(event.getHeader()); tableMetaCache.apply(position, event.getDbName(), queryString, null); } /* 传递参数position,是尝试根据dump到不同位点位置的binlog使用不同的table schema进行解析,这里的逻辑是没有实现吗? */ public boolean apply(EntryPosition position, String schema, String ddl, String extra) { tableMetas.clear(); synchronized (this) { if (StringUtils.isNotEmpty(schema)) { repository.setDefaultSchema(schema); }
try {
// druid暂时flush privileges语法解析有问题
if (!StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "flush")
&& !StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "grant")
&& !StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "revoke")
&& !StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "create user")
&& !StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "alter user")
&& !StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "drop user")
&& !StringUtils.startsWithIgnoreCase(StringUtils.trim(ddl), "create database")) {
repository.console(ddl);
}
} catch (Throwable e) {
logger.warn("parse faield : " + ddl, e);
}
}
// TableMeta meta = find("tddl5_00", "ab");
// if (meta != null) {
// repository.setDefaultSchema("tddl5_00");
// System.out.println(repository.console("show create table tddl5_00.ab"));
// System.out.println(repository.console("show columns from tddl5_00.ab"));
// }
return true;
}
public void setDefaultSchema(String name) { if (name == null) { this.defaultSchema = null; } else { String normalizedName = SQLUtils.normalize(name).toLowerCase(); Schema defaultSchema = (Schema)this.schemas.get(normalizedName); if (defaultSchema != null) { this.defaultSchema = defaultSchema; } else if (this.defaultSchema != null && this.defaultSchema.getName() == null) { this.defaultSchema.setName(name); this.schemas.put(normalizedName, this.defaultSchema); } else { defaultSchema = new Schema(this); defaultSchema.setName(name); this.schemas.put(normalizedName, defaultSchema); this.defaultSchema = defaultSchema; } } }
原提问者GitHub用户tsywkGo
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
升级druid版本为1.2.6后已解决,会正确处理create table if not exist的合并语义
原回答者GitHub用户agapple