查询与保存 效率问题 返回

实体结构:
public class table1 表中含8605行数据
{
public string ID{ get; set; }
public string bb{ get; set; }
.....
[SqlSugar.SugarColumn(IsIgnore = true)]
public List<table2>cc{ get; set; }
}
-----------------------------------------------------------
public class table2 表中含11243行数据
{
public string ID{ get; set; }
public string table1_ID{ get; set; }
.....
[SqlSugar.SugarColumn(IsIgnore = true)]
public List<table3>cc{ get; set; }
[SqlSugar.SugarColumn(IsIgnore = true)]
public List<table4>dd{ get; set; }
}
-----------------------------------------------------------
public class table3 表中含1669000行
{
public string ID{ get; set; }
public string table2 _ID{ get; set; }
.....
}
-----------------------------------------------------------
public class table4 表中含2818734行数据
{
public string ID{ get; set; }
public string table2 _ID{ get; set; }
.....
}
-----------------------------------------------------------
问题1:查询table1中某个ID的数据,以及它的子表数据,耗时1.5s , 还能提升吗? 数据库postgerSQL
table1 result = this.Db.Queryable<table1>().First(i => i.Id == "123456");
result .cc= this.Db.Queryable<table2>().Where(i => i.table1_ID== "123456").ToList();
if (result .cc.Count > 0)
{
foreach (var item in result .cc)
{
item .cc= this.Db.Queryable<table3>().Where(i => i.table2_ID== item .Id).ToList();
item .dd= this.Db.Queryable<table4>().Where(i => i.table2_ID== item .Id).ToList();
}
}
问题2: 插入耗时长,table1(一行数据) table2(4行数据) table3(1350*4行数据) table4(2700*4行数据) 数据库postgerSQL
Insertable(table1).ExecuteCommand();
InsertRange(table2);
InsertRange(table3);
InsertRange(table4);
插入以上数据,耗时2分钟,InsertRange换成BulkCopy也耗时1分钟,
求指导提升效率。
热忱回答(9)
-
fate sta VIP0
2周前是不是远程
0 回复 -
fate sta VIP0
2周前如果是远程算正常速度,本地就不正常可以提供DEMO
0 回复 -
小白 VIP0
2周前@fate sta:是本地 不是远程
0 回复 -
fate sta VIP0
2周前@小白:https://www.donet5.com/Home/Doc?typeId=2366 按这个格式写一个可以重现的DEMO 暂时没遇到你这种情况
0 回复 -
fate sta VIP0
2周前正常普通1万都不需要1秒,你是不是特殊类型比如JSON 之类的
0 回复 -
fate sta VIP0
2周前或者比较大的字段
0 回复 -
小白 VIP0
2周前@fate sta:都是int string 这类常用的 只是表里字段比较多 table3 table4都含三四个字段
0 回复 -
fate sta VIP0
2周前@小白:那就按上面的链接提供DEMO吧,也可能是表的问题
0 回复 -
小白 VIP0
2周前@fate sta:找到了问题,因为两个大表是GUID做的主键,删掉主键后插入提升到4秒。
0 回复