- 修复 pgsql WithTempQuery + ToList 对于 bool 类型处理导致的性能问题;#2093

This commit is contained in:
28810
2025-08-14 12:28:46 +08:00
parent ab5a6a3533
commit 62bd9afcdf
7 changed files with 375 additions and 18 deletions

View File

@@ -33,7 +33,25 @@ namespace FreeSql.KingbaseES
{
switch (exp.Type.NullableTypeOrThis().ToString())
{
case "System.Boolean": return $"(({getExp(operandExp)})::varchar not in ('0','false','f','no'))";
case "System.Boolean":
var boolstr = getExp(operandExp);
switch (boolstr)
{
case "0":
case "'0'":
case "false":
case "'f'":
case "'no'":
return "'f'::bool";
case "1":
case "'1'":
case "true":
case "'t'":
case "'yes'":
return "'t'::bool";
default:
return $"(({boolstr})::varchar not in ('0','false','f','no'))";
}
case "System.Byte": return $"({getExp(operandExp)})::int2";
case "System.Char": return $"substr(({getExp(operandExp)})::char, 1, 1)";
case "System.DateTime": return ExpressionConstDateTime(operandExp) ?? $"({getExp(operandExp)})::timestamp";
@@ -61,7 +79,25 @@ namespace FreeSql.KingbaseES
case "TryParse":
switch (callExp.Method.DeclaringType.NullableTypeOrThis().ToString())
{
case "System.Boolean": return $"(({getExp(callExp.Arguments[0])})::varchar not in ('0','false','f','no'))";
case "System.Boolean":
var boolstr = getExp(callExp.Arguments[0]);
switch (boolstr)
{
case "0":
case "'0'":
case "false":
case "'f'":
case "'no'":
return "'f'::bool";
case "1":
case "'1'":
case "true":
case "'t'":
case "'yes'":
return "'t'::bool";
default:
return $"(({boolstr})::varchar not in ('0','false','f','no'))";
}
case "System.Byte": return $"({getExp(callExp.Arguments[0])})::int2";
case "System.Char": return $"substr(({getExp(callExp.Arguments[0])})::char, 1, 1)";
case "System.DateTime": return ExpressionConstDateTime(callExp.Arguments[0]) ?? $"({getExp(callExp.Arguments[0])})::timestamp";
@@ -620,7 +656,25 @@ namespace FreeSql.KingbaseES
{
switch (exp.Method.Name)
{
case "ToBoolean": return $"(({getExp(exp.Arguments[0])})::varchar not in ('0','false','f','no'))";
case "ToBoolean":
var boolstr = getExp(exp.Arguments[0]);
switch (boolstr)
{
case "0":
case "'0'":
case "false":
case "'f'":
case "'no'":
return "'f'::bool";
case "1":
case "'1'":
case "true":
case "'t'":
case "'yes'":
return "'t'::bool";
default:
return $"(({boolstr})::varchar not in ('0','false','f','no'))";
}
case "ToByte": return $"({getExp(exp.Arguments[0])})::int2";
case "ToChar": return $"substr(({getExp(exp.Arguments[0])})::char, 1, 1)";
case "ToDateTime": return ExpressionConstDateTime(exp.Arguments[0]) ?? $"({getExp(exp.Arguments[0])})::timestamp";