Mycat源码解读--错误之【op table not in schema】

1、[Err] 1064 - op table not in schema----INDEX

备注:这种错误一般是表名字获取失败报的错误,

具体位置是: RouterUtil类中的routeToDDLNode方法报的


Mycat源码解读--错误之【op table not in schema】_第1张图片

/**

* 修复DDL路由

*

* @return RouteResultset

* @author aStoneGod

*/

    public static RouteResultset routeToDDLNode(RouteResultset rrs, int sqlType, 

                String stmt,SchemaConfig schema) throws SQLSyntaxErrorException {

stmt = getFixedSql(stmt);

String tablename = "";

final String upStmt = stmt.toUpperCase();

if(upStmt.startsWith("CREATE")){

  if (upStmt.contains("CREATE INDEX ")){//如果create Index之间的空格不匹配也会报错

tablename = RouterUtil.getTableName(stmt, RouterUtil.getCreateIndexPos(upStmt, 0));

  }else {//Create View/Table/CREATE SYNONYM统一执行此处代码

                           //(创建表, 索引, 视图, 同义词, 过程, 函数, 数据库链接等)

                           //create user username identified by password;

tablename = RouterUtil.getTableName(stmt, RouterUtil.getCreateTablePos(upStmt, 0));

}

}else if(upStmt.startsWith("DROP")){

if (upStmt.contains("DROP INDEX ")){

tablename = RouterUtil.getTableName(stmt, RouterUtil.getDropIndexPos(upStmt, 0));

}else {

tablename = RouterUtil.getTableName(stmt, RouterUtil.getDropTablePos(upStmt, 0));

}

}else if(upStmt.startsWith("ALTER")){

tablename = RouterUtil.getTableName(stmt, RouterUtil.getAlterTablePos(upStmt, 0));

}else if (upStmt.startsWith("TRUNCATE")){

tablename = RouterUtil.getTableName(stmt, RouterUtil.getTruncateTablePos(upStmt, 0));

}

tablename = tablename.toUpperCase();

 

if (schema.getTables().containsKey(tablename)){

//此处省略部分代码

return rrs;

}else if(schema.getDataNode()!=null){//默认节点ddl

RouteResultsetNode[] nodes = new RouteResultsetNode[1];

nodes[0] = new RouteResultsetNode(schema.getDataNode(), sqlType, stmt);

nodes[0].setSource(rrs);

rrs.setNodes(nodes);

return rrs;

}

//both tablename and defaultnode null

LOGGER.error("table not in schema----"+tablename);

throw new SQLSyntaxErrorException("op table not in schema----"+tablename);

}


Mycat源码解读--错误之【op table not in schema】_第2张图片
 空格恰到好处就OK


Mycat源码解读--错误之【op table not in schema】_第3张图片
 

你可能感兴趣的:(Mycat中间件)