使用环境:
通过Spring 命名空间方式集成了ShardingSphere-JDBC 5.2.0
环境1:
windows7 MySQL5.7.30
环境2:
MySQL 5.7.30
场景、问题:
执行如下SQL,查询结果不一致,实际数据库查询结果为:10275
已进行操作:
环境1:
2023-03-03 16:48:24.429 [pool-10-thread-1] [INFO]-[ShardingSphere-SQL] Logic SQL: SELECT COUNT(m.id) AS COUNT_R FROM model_dict m INNER JOIN model_dict_tag t ON m.id = t.base_dictionary_id WHERE t.val in ('介入治疗','手术') AND m.is_deleted = 0
2023-03-03 16:48:24.430 [pool-10-thread-1] [INFO]-[ShardingSphere-SQL] SQLStatement: MySQLSelectStatement(super=SelectStatement(super=AbstractSQLStatement(parameterCount=0, parameterMarkerSegments=[], commentSegments=[]), projections=ProjectionsSegment(startIndex=7, stopIndex=28, projections=[AggregationProjectionSegment(startIndex=7, stopIndex=17, type=COUNT, innerExpression=(m.id), parameters=[ColumnSegment(startIndex=13, stopIndex=16, identifier=IdentifierValue(value=id, quoteCharacter=NONE), owner=Optional[OwnerSegment(startIndex=13, stopIndex=13, identifier=IdentifierValue(value=m, quoteCharacter=NONE), owner=Optional.empty)])], alias=Optional[COUNT_R])], distinctRow=false), from=JoinTableSegment(startIndex=35, stopIndex=105, alias=Optional.empty, left=SimpleTableSegment(tableName=TableNameSegment(startIndex=35, stopIndex=44, identifier=IdentifierValue(value=model_dict, quoteCharacter=NONE)), owner=Optional.empty, alias=Optional[m]), joinType=INNER, right=SimpleTableSegment(tableName=TableNameSegment(startIndex=59, stopIndex=72, identifier=IdentifierValue(value=model_dict_tag, quoteCharacter=NONE)), owner=Optional.empty, alias=Optional[t]), condition=BinaryOperationExpression(startIndex=79, stopIndex=105, left=ColumnSegment(startIndex=79, stopIndex=82, identifier=IdentifierValue(value=id, quoteCharacter=NONE), owner=Optional[OwnerSegment(startIndex=79, stopIndex=79, identifier=IdentifierValue(value=m, quoteCharacter=NONE), owner=Optional.empty)]), right=ColumnSegment(startIndex=86, stopIndex=105, identifier=IdentifierValue(value=base_dictionary_id, quoteCharacter=NONE), owner=Optional[OwnerSegment(startIndex=86, stopIndex=86, identifier=IdentifierValue(value=t, quoteCharacter=NONE), owner=Optional.empty)]), operator==, text=m.id = t.base_dictionary_id), using=[]), where=Optional[WhereSegment(startIndex=107, stopIndex=155, expr=BinaryOperationExpression(startIndex=113, stopIndex=155, left=InExpression(startIndex=113, stopIndex=134, left=ColumnSegment(startIndex=113, stopIndex=117, identifier=IdentifierValue(value=val, quoteCharacter=NONE), owner=Optional[OwnerSegment(startIndex=113, stopIndex=113, identifier=IdentifierValue(value=t, quoteCharacter=NONE), owner=Optional.empty)]), right=ListExpression(startIndex=122, stopIndex=134, items=[LiteralExpressionSegment(startIndex=123, stopIndex=128, literals=介入治疗), LiteralExpressionSegment(startIndex=130, stopIndex=133, literals=手术)]), not=false), right=BinaryOperationExpression(startIndex=140, stopIndex=155, left=ColumnSegment(startIndex=140, stopIndex=151, identifier=IdentifierValue(value=is_deleted, quoteCharacter=NONE), owner=Optional[OwnerSegment(startIndex=140, stopIndex=140, identifier=IdentifierValue(value=m, quoteCharacter=NONE), owner=Optional.empty)]), right=LiteralExpressionSegment(startIndex=155, stopIndex=155, literals=0), operator==, text=m.is_deleted = 0), operator=AND, text=t.val in ('介入治疗','手术') AND m.is_deleted = 0))], groupBy=Optional.empty, having=Optional.empty, orderBy=Optional.empty, combines=[]), table=Optional.empty, limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
2023-03-03 16:48:24.430 [pool-10-thread-1] [INFO]-[ShardingSphere-SQL] Actual SQL: ds ::: SELECT COUNT(m.id) AS COUNT_R FROM model_dict m INNER JOIN model_dict_tag t ON m.id = t.base_dictionary_id WHERE t.val in ('介入治疗','手术') AND m.is_deleted = 0
2023-03-03 16:48:24.687 [pool-10-thread-1] [INFO]-[org.***.***.dao.******DaoImpl] ------------------------------:10275
环境2:
2023-03-03 16:37:48.403 [pool-10-thread-2] [INFO]-[ShardingSphere-SQL] Logic SQL: SELECT COUNT(m.id) AS COUNT_R FROM model_dict m INNER JOIN model_dict_tag t ON m.id = t.base_dictionary_id WHERE t.val in ('介入治疗','手术') AND m.is_deleted = 0
2023-03-03 16:37:48.404 [pool-10-thread-2] [INFO]-[ShardingSphere-SQL] SQLStatement: MySQLSelectStatement(super=SelectStatement(super=AbstractSQLStatement(parameterCount=0, parameterMarkerSegments=[], commentSegments=[]), projections=ProjectionsSegment(startIndex=7, stopIndex=28, projections=[AggregationProjectionSegment(startIndex=7, stopIndex=17, type=COUNT, innerExpression=(m.id), parameters=[ColumnSegment(startIndex=13, stopIndex=16, identifier=IdentifierValue(value=id, quoteCharacter=NONE), owner=Optional[OwnerSegment(startIndex=13, stopIndex=13, identifier=IdentifierValue(value=m, quoteCharacter=NONE), owner=Optional.empty)])], alias=Optional[COUNT_R])], distinctRow=false), from=JoinTableSegment(startIndex=35, stopIndex=105, alias=Optional.empty, left=SimpleTableSegment(tableName=TableNameSegment(startIndex=35, stopIndex=44, identifier=IdentifierValue(value=model_dict, quoteCharacter=NONE)), owner=Optional.empty, alias=Optional[m]), joinType=INNER, right=SimpleTableSegment(tableName=TableNameSegment(startIndex=59, stopIndex=72, identifier=IdentifierValue(value=model_dict_tag, quoteCharacter=NONE)), owner=Optional.empty, alias=Optional[t]), condition=BinaryOperationExpression(startIndex=79, stopIndex=105, left=ColumnSegment(startIndex=79, stopIndex=82, identifier=IdentifierValue(value=id, quoteCharacter=NONE), owner=Optional[OwnerSegment(startIndex=79, stopIndex=79, identifier=IdentifierValue(value=m, quoteCharacter=NONE), owner=Optional.empty)]), right=ColumnSegment(startIndex=86, stopIndex=105, identifier=IdentifierValue(value=base_dictionary_id, quoteCharacter=NONE), owner=Optional[OwnerSegment(startIndex=86, stopIndex=86, identifier=IdentifierValue(value=t, quoteCharacter=NONE), owner=Optional.empty)]), operator==, text=m.id = t.base_dictionary_id), using=[]), where=Optional[WhereSegment(startIndex=107, stopIndex=155, expr=BinaryOperationExpression(startIndex=113, stopIndex=155, left=InExpression(startIndex=113, stopIndex=134, left=ColumnSegment(startIndex=113, stopIndex=117, identifier=IdentifierValue(value=val, quoteCharacter=NONE), owner=Optional[OwnerSegment(startIndex=113, stopIndex=113, identifier=IdentifierValue(value=t, quoteCharacter=NONE), owner=Optional.empty)]), right=ListExpression(startIndex=122, stopIndex=134, items=[LiteralExpressionSegment(startIndex=123, stopIndex=128, literals=介入治疗), LiteralExpressionSegment(startIndex=130, stopIndex=133, literals=手术)]), not=false), right=BinaryOperationExpression(startIndex=140, stopIndex=155, left=ColumnSegment(startIndex=140, stopIndex=151, identifier=IdentifierValue(value=is_deleted, quoteCharacter=NONE), owner=Optional[OwnerSegment(startIndex=140, stopIndex=140, identifier=IdentifierValue(value=m, quoteCharacter=NONE), owner=Optional.empty)]), right=LiteralExpressionSegment(startIndex=155, stopIndex=155, literals=0), operator==, text=m.is_deleted = 0), operator=AND, text=t.val in ('介入治疗','手术') AND m.is_deleted = 0))], groupBy=Optional.empty, having=Optional.empty, orderBy=Optional.empty, combines=[]), table=Optional.empty, limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
2023-03-03 16:37:48.404 [pool-10-thread-2] [INFO]-[ShardingSphere-SQL] Actual SQL: ds ::: SELECT COUNT(m.id) AS COUNT_R FROM model_dict m INNER JOIN model_dict_tag t ON m.id = t.base_dictionary_id WHERE t.val in ('介入治疗','手术') AND m.is_deleted = 0
2023-03-03 16:37:48.514 [pool-10-thread-2] [INFO]-[org.***.***.dao.******DaoImpl] ------------------------------:0