Shardingsphere4.1.1版本坑

更新时间:2023-05-16 03:55:05 阅读: 评论:0

Shardingsphere4.1.1版本坑
SELECT
COUNT(*)
FROM
(
SELECT
XXX
FROM
XXX r
LEFT JOIN YYY d ON r.id = d.resource_position_id
ant_code = '10001'
WHERE
1 = 1
AND r.custom_id = ?
AND r.is_deleted = 'N'
ant_code = '10001'
GROUP BY
r.id
) TOTAL
1、SelectStatementContext 初始化
public SelectStatementContext(SelectStatement sqlStatement, GroupByContext groupByContext, OrderByContext orderByContext, ProjectionsContext p        super(sqlStatement);olans
this.tablesContext = new SimpleTableSegments());
离职英文
圆梦教育培训学校derByContext = orderByContext;
this.projectionsContext = projectionsContext;
this.paginationContext = paginationContext;
}
2、注意
this.tablesContext = new SimpleTableSegments());
efSelectStatement.java
public Collection<SimpleTableSegment> getSimpleTableSegments() {
Collection<SimpleTableSegment> result = new LinkedList();
Iterator var2 = this.tableReferences.iterator();
公务员考试考哪几科while(var2.hasNext()) {
TableReferenceSegment each = (();
result.Tables());
}
return result;
}
TableReferenceSegment.java
public Collection<SimpleTableSegment> getTables() {
Collection<SimpleTableSegment> tables = new LinkedList();
if (null != this.tableFactor && Table() instanceof SimpleTableSegment) {
tables.add((SimpleTableSegment)Table());
}
if (!this.joinedTables.isEmpty()) {
Iterator var2 = this.joinedTables.iterator();
while(var2.hasNext()) {
JoinedTableSegment each = (();
if (null != Table()) {
tables.add((Table());
}
}
}
此时tableFactor的类型为SubquerySegment(startIndex=21, stopIndex=555,
lect=org.apache.shardingsphere.sql.parr.sql.statement.dml.SelectStatement@8a91e92),getTables拿到的是空集合
3、执⾏查询时,实例化路由引擎
ShardingRouteEngineFactory.java
public static ShardingRouteEngine newInstance(ShardingRule shardingRule, ShardingSphereMetaData metaData, SQLStatementContext sqlStatementCo
SQLStatement sqlStatement = SqlStatement();
Collection<String> tableNames = TablesContext().getTableNames();
if (sqlStatement instanceof TCLStatement) {
return new ShardingDatabaBroadcastRoutingEngine();
} el if (sqlStatement instanceof DDLStatement) {
return new Schema(), sqlStatementContext);
tifosi} el if (sqlStatement instanceof DALStatement) {
return getDALRoutingEngine(shardingRule, sqlStatement, tableNames);
} el if (sqlStatement instanceof DCLStatement) {
return getDCLRoutingEngine(sqlStatementContext, metaData);
} el if (shardingRule.isAllInDefaultDataSource(tableNames)) {
return new ShardingDefaultDatabaRoutingEngine(tableNames);
} el if (shardingRule.isAllBroadcastTables(tableNames)) {
return (ShardingRouteEngine)(sqlStatement instanceof SelectStatement ? new ShardingUnicastRoutingEngine(tableNames) : new ShardingDatabaBroa        } el if (SqlStatement() instanceof DMLStatement && tableNames.isEmpty() && shardingRule.hasDefaultDataSourceName()) {
return new ShardingDefaultDatabaRoutingEngine(tableNames);
} el {
return (ShardingRouteEngine)((!(SqlStatement() instanceof DMLStatement) || !shardingConditions.isAlwaysFal()) && !tableNam        }
}
此时,tableNames,拿到的是空,因为第1步,初始化时,tables是空,最后⼀步拿到的是默认随机路由引擎
ShardingUnicastRoutingEngine
4、路由问题
ShardingUnicastRoutingEngine.java
public RouteResult route(ShardingRule shardingRule) {
RouteResult result = new RouteResult();
String dataSourceName = ShardingDataSourceNames().getRandomDataSourceName();
RouteMapper dataSourceMapper = new RouteMapper(dataSourceName, dataSourceName);
ArrayList tableMappers;
if (shardingRule.isAllBroadcastTables(this.logicTables)) {
tableMappers = new ArrayList(this.logicTables.size());complete是什么意思
Iterator var6 = this.logicTables.iterator();
while(var6.hasNext()) {
String each = (();
tableMappers.add(new RouteMapper(each, each));
}
} el if (this.logicTables.isEmpty()) {
} el if (1 == this.logicTables.size()) {
String logicTableName = (String)this.logicTables.iterator().next();
if (!shardingRule.findTableRule(logicTableName).isPrent()) {
大学英语课堂游戏
return result;
}
DataNode dataNode = DataNode(logicTableName);
tableMappers = new ArrayList(this.logicTables.size());
Set<String> availableDatasourceNames = null;
boolean first = true;
Iterator var8 = this.logicTables.iterator();
while(var8.hasNext()) {
String each = (();
TableRule tableRule = TableRule(each);
夏季如何保养皮肤DataNode dataNode = (ActualDataNodes().get(0);
tableMappers.add(new RouteMapper(each, TableName()));
Set<String> currentDataSourceNames = new ActualDatasourceNames().size());
micheal
Iterator var13 = ActualDataNodes().iterator();
while(var13.hasNext()) {
DataNode eachDataNode = (();
currentDataSourceNames.DataSourceName());
}
if (first) {
availableDatasourceNames = currentDataSourceNames;
first = fal;
} el {
availableDatasourceNames = Sets.interction((Set)availableDatasourceNames, currentDataSourceNames);
}
}
if (((Set)availableDatasourceNames).isEmpty()) {
throw new ShardingSphereConfigurationException("Cannot find actual datasource interction for logic tables: %s", new Object[]{this.logicTables});
}
dataSourceName = ShardingDataSourceNames().getRandomDataSourceName((Collection)availableDatasourceNames);
}
return result;
}
String dataSourceName = ShardingDataSourceNames().getRandomDataSourceName();数据源是个随机出来的数据源,不⾛分库算法

本文发布于:2023-05-16 03:55:05,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/110151.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:路由   引擎   数据源   默认
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图