Mycat source code interpretation--error [op table not in schema]

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

Note: This kind of error is generally the error reported by the failure to obtain the table name.

The specific location is: Reported by the routeToDDLNode method  in the RouterUtil class




/**

* Fix DDL routing

*

* @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 ")){// If the spaces between create Index do not match, an error will also be reported

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

  }else {// Create View/Table / CREATE  SYNONYM execute the code here uniformly

                           // (create tables, indexes, views, synonyms, procedures, functions, database links, etc.)

                           //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)){

// part of the code is omitted here

return rrs;

}else if(schema.getDataNode()!=null){//Default node 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);

}



 The space is just right



 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326797194&siteId=291194637