添加分表的同条件查询是否追踪单元测试
This commit is contained in:
parent
179bd6c801
commit
3270e789ae
|
@ -30,7 +30,7 @@ Release | EF Core | .NET | .NET (Core)
|
||||||
## 快速开始
|
## 快速开始
|
||||||
5步实现按月分表,且支持自动化建表建库
|
5步实现按月分表,且支持自动化建表建库
|
||||||
### 第一步安装依赖
|
### 第一步安装依赖
|
||||||
|
`ShardingCore`版本表现形式为a.b.c.d,其中a表示`efcore`的版本号,b表示`ShardingCore`的主版本号,c表示`ShardingCore`次级版本号,d表示`ShardingCore`的修订版本号
|
||||||
```shell
|
```shell
|
||||||
# 请对应安装您需要的版本
|
# 请对应安装您需要的版本
|
||||||
PM> Install-Package ShardingCore
|
PM> Install-Package ShardingCore
|
||||||
|
@ -38,6 +38,7 @@ PM> Install-Package ShardingCore
|
||||||
PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer
|
PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer
|
||||||
# use mysql
|
# use mysql
|
||||||
#PM> Install-Package Pomelo.EntityFrameworkCore.MySql
|
#PM> Install-Package Pomelo.EntityFrameworkCore.MySql
|
||||||
|
# use other database driver,if efcore support
|
||||||
```
|
```
|
||||||
|
|
||||||
### 第二步创建查询对象
|
### 第二步创建查询对象
|
||||||
|
@ -238,6 +239,7 @@ AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores
|
||||||
|----------------------------------- |--- |---------:|----------:|----------:|
|
|----------------------------------- |--- |---------:|----------:|----------:|
|
||||||
| NoShardingIndexFirstOrDefaultAsync | 10 | 1.512 ms | 0.0071 ms | 0.0063 ms |
|
| NoShardingIndexFirstOrDefaultAsync | 10 | 1.512 ms | 0.0071 ms | 0.0063 ms |
|
||||||
| ShardingIndexFirstOrDefaultAsync | 10 | 1.567 ms | 0.0127 ms | 0.0113 ms |
|
| ShardingIndexFirstOrDefaultAsync | 10 | 1.567 ms | 0.0127 ms | 0.0113 ms |
|
||||||
|
|
||||||
针对未分片数据的查询性能,可以看出10次查询差距为0.05ms,单次查询损耗约为5微妙=0.005毫秒,损耗占比为3%,
|
针对未分片数据的查询性能,可以看出10次查询差距为0.05ms,单次查询损耗约为5微妙=0.005毫秒,损耗占比为3%,
|
||||||
|
|
||||||
结论:efcore 原生查询和sharding-core的查询在针对未分片对象查询上性能可达原先的97%具有极高的性能
|
结论:efcore 原生查询和sharding-core的查询在针对未分片对象查询上性能可达原先的97%具有极高的性能
|
||||||
|
|
|
@ -537,6 +537,7 @@ namespace ShardingCore.Test
|
||||||
var sysUserMod = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefaultAsync();
|
var sysUserMod = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefaultAsync();
|
||||||
Assert.NotNull(sysUserMod);
|
Assert.NotNull(sysUserMod);
|
||||||
Assert.True(sysUserMod.Id == "1");
|
Assert.True(sysUserMod.Id == "1");
|
||||||
|
Assert.Equal(sysUserModaa, sysUserMod);
|
||||||
var sysUserModxx = await _virtualDbContext.Set<SysUserMod>().Where(o =>x.Contains(o.Id)).FirstOrDefaultAsync();
|
var sysUserModxx = await _virtualDbContext.Set<SysUserMod>().Where(o =>x.Contains(o.Id)).FirstOrDefaultAsync();
|
||||||
Assert.NotNull(sysUserModxx);
|
Assert.NotNull(sysUserModxx);
|
||||||
Assert.True(x.Contains(sysUserModxx.Id) );
|
Assert.True(x.Contains(sysUserModxx.Id) );
|
||||||
|
|
|
@ -462,6 +462,7 @@ namespace ShardingCore.Test
|
||||||
Assert.True(sysUserMod.Id == "1");
|
Assert.True(sysUserMod.Id == "1");
|
||||||
var sysUserModxx = _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefault();
|
var sysUserModxx = _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefault();
|
||||||
Assert.NotNull(sysUserModxx);
|
Assert.NotNull(sysUserModxx);
|
||||||
|
Assert.Equal(sysUserModaa, sysUserMod);
|
||||||
Assert.True(x.Contains(sysUserModxx.Id));
|
Assert.True(x.Contains(sysUserModxx.Id));
|
||||||
Assert.NotNull(sysUserMod);
|
Assert.NotNull(sysUserMod);
|
||||||
var userMod = _virtualDbContext.Set<SysUserMod>().Find("1");
|
var userMod = _virtualDbContext.Set<SysUserMod>().Find("1");
|
||||||
|
|
|
@ -495,6 +495,7 @@ namespace ShardingCore.Test2x
|
||||||
var sysUserMod = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefaultAsync();
|
var sysUserMod = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefaultAsync();
|
||||||
Assert.NotNull(sysUserMod);
|
Assert.NotNull(sysUserMod);
|
||||||
Assert.True(sysUserMod.Id == "1");
|
Assert.True(sysUserMod.Id == "1");
|
||||||
|
Assert.Equal(sysUserModaa, sysUserMod);
|
||||||
var sysUserModxx = await _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefaultAsync();
|
var sysUserModxx = await _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefaultAsync();
|
||||||
Assert.NotNull(sysUserModxx);
|
Assert.NotNull(sysUserModxx);
|
||||||
Assert.True(x.Contains(sysUserModxx.Id));
|
Assert.True(x.Contains(sysUserModxx.Id));
|
||||||
|
|
|
@ -458,6 +458,7 @@ namespace ShardingCore.Test2x
|
||||||
var sysUserMod = _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefault();
|
var sysUserMod = _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefault();
|
||||||
Assert.NotNull(sysUserMod);
|
Assert.NotNull(sysUserMod);
|
||||||
Assert.True(sysUserMod.Id == "1");
|
Assert.True(sysUserMod.Id == "1");
|
||||||
|
Assert.Equal(sysUserModaa, sysUserMod);
|
||||||
var sysUserModxx = _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefault();
|
var sysUserModxx = _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefault();
|
||||||
Assert.NotNull(sysUserModxx);
|
Assert.NotNull(sysUserModxx);
|
||||||
Assert.True(x.Contains(sysUserModxx.Id));
|
Assert.True(x.Contains(sysUserModxx.Id));
|
||||||
|
|
|
@ -494,6 +494,7 @@ namespace ShardingCore.Test3x
|
||||||
var sysUserMod = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefaultAsync();
|
var sysUserMod = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefaultAsync();
|
||||||
Assert.NotNull(sysUserMod);
|
Assert.NotNull(sysUserMod);
|
||||||
Assert.True(sysUserMod.Id == "1");
|
Assert.True(sysUserMod.Id == "1");
|
||||||
|
Assert.Equal(sysUserModaa, sysUserMod);
|
||||||
var sysUserModxx = await _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefaultAsync();
|
var sysUserModxx = await _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefaultAsync();
|
||||||
Assert.NotNull(sysUserModxx);
|
Assert.NotNull(sysUserModxx);
|
||||||
Assert.True(x.Contains(sysUserModxx.Id));
|
Assert.True(x.Contains(sysUserModxx.Id));
|
||||||
|
|
|
@ -460,6 +460,7 @@ namespace ShardingCore.Test3x
|
||||||
var sysUserMod = _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefault();
|
var sysUserMod = _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefault();
|
||||||
Assert.NotNull(sysUserMod);
|
Assert.NotNull(sysUserMod);
|
||||||
Assert.True(sysUserMod.Id == "1");
|
Assert.True(sysUserMod.Id == "1");
|
||||||
|
Assert.Equal(sysUserModaa, sysUserMod);
|
||||||
var sysUserModxx = _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefault();
|
var sysUserModxx = _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefault();
|
||||||
Assert.NotNull(sysUserModxx);
|
Assert.NotNull(sysUserModxx);
|
||||||
Assert.True(x.Contains(sysUserModxx.Id));
|
Assert.True(x.Contains(sysUserModxx.Id));
|
||||||
|
|
|
@ -494,6 +494,7 @@ namespace ShardingCore.Test5x
|
||||||
var sysUserMod = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefaultAsync();
|
var sysUserMod = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefaultAsync();
|
||||||
Assert.NotNull(sysUserMod);
|
Assert.NotNull(sysUserMod);
|
||||||
Assert.True(sysUserMod.Id == "1");
|
Assert.True(sysUserMod.Id == "1");
|
||||||
|
Assert.Equal(sysUserModaa, sysUserMod);
|
||||||
var sysUserModxx = await _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefaultAsync();
|
var sysUserModxx = await _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefaultAsync();
|
||||||
Assert.NotNull(sysUserModxx);
|
Assert.NotNull(sysUserModxx);
|
||||||
Assert.True(x.Contains(sysUserModxx.Id));
|
Assert.True(x.Contains(sysUserModxx.Id));
|
||||||
|
|
|
@ -459,6 +459,7 @@ namespace ShardingCore.Test5x
|
||||||
var sysUserMod = _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefault();
|
var sysUserMod = _virtualDbContext.Set<SysUserMod>().Where(o => o.Id == "1").FirstOrDefault();
|
||||||
Assert.NotNull(sysUserMod);
|
Assert.NotNull(sysUserMod);
|
||||||
Assert.True(sysUserMod.Id == "1");
|
Assert.True(sysUserMod.Id == "1");
|
||||||
|
Assert.Equal(sysUserModaa, sysUserMod);
|
||||||
var sysUserModxx = _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefault();
|
var sysUserModxx = _virtualDbContext.Set<SysUserMod>().Where(o => x.Contains(o.Id)).FirstOrDefault();
|
||||||
Assert.NotNull(sysUserModxx);
|
Assert.NotNull(sysUserModxx);
|
||||||
Assert.True(x.Contains(sysUserModxx.Id));
|
Assert.True(x.Contains(sysUserModxx.Id));
|
||||||
|
|
Loading…
Reference in New Issue