Optimize MYSQL 5.6 COUNT Slow

This commit is contained in:
sunkaixuan
2019-02-10 14:26:56 +08:00
parent 5828c5b09d
commit c07ab9298d
3 changed files with 15 additions and 5 deletions

View File

@@ -8,8 +8,8 @@ namespace OrmTest
{ {
public class Config public class Config
{ {
public static string ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=root"; public static string ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql";
public static string ConnectionString2 = "server=localhost;Database=SQLSUGAR4XTEST;Uid=root;Pwd=root"; public static string ConnectionString2 = "server=localhost;Database=SQLSUGAR4XTEST;Uid=root;Pwd=haosql";
public static string ConnectionString3 = "server=localhost;Database=sqlsugar4xtest;Uid=root;Pwd=root"; public static string ConnectionString3 = "server=localhost;Database=sqlsugar4xtest;Uid=root;Pwd=haosql";
} }
} }

View File

@@ -260,6 +260,12 @@ namespace OrmTest.Demo
//skip5 //skip5
var skip5 = db.Queryable<Student>().Skip(5).ToList(); var skip5 = db.Queryable<Student>().Skip(5).ToList();
var page2 = db.Queryable<Student>().Where(it=>it.Id>0).ToPageList(1,2,ref totalCount);
var page3 = db.SqlQueryable<Student>("SELECT * FROM Student").ToPageList(1, 2, ref totalCount);
} }
public static void Where() public static void Where()
{ {
@@ -332,9 +338,10 @@ namespace OrmTest.Demo
.Select((st, sc, sc2) => new { st.Name, st.Id, schoolName = sc.Name, schoolName2 = sc2.Name }).ToPageList(1,2); .Select((st, sc, sc2) => new { st.Name, st.Id, schoolName = sc.Name, schoolName2 = sc2.Name }).ToPageList(1,2);
//join 3 table page //join 3 table page
int count = 0;
var list8 = db.Queryable<Student, School, School>((st, sc, sc2) => st.SchoolId == sc.Id && sc.Id == sc2.Id) var list8 = db.Queryable<Student, School, School>((st, sc, sc2) => st.SchoolId == sc.Id && sc.Id == sc2.Id)
.OrderBy(st=>st.Id) .OrderBy(st=>st.Id)
.Select((st, sc, sc2) => new { st.Name, st.Id, schoolName = sc.Name, schoolName2 = sc2.Name }).ToPageList(1, 2); .Select((st, sc, sc2) => new { st.Name, st.Id, schoolName = sc.Name, schoolName2 = sc2.Name }).ToPageList(1, 2,ref count);
} }
public static void Funs() public static void Funs()
{ {

View File

@@ -63,7 +63,10 @@ namespace SqlSugar
this.OrderByValue = oldOrderValue; this.OrderByValue = oldOrderValue;
return result; return result;
} }
public override string ToCountSql(string sql)
{
return Regex.Replace(sql,"^SELECT .+? FROM ", "SELECT COUNT(*) FROM ");
}
#endregion #endregion
#region Get SQL Partial #region Get SQL Partial