updates delete query to work with MySql
This commit is contained in:
@@ -33,7 +33,24 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenFiveZer
|
||||
|
||||
if (found != null)
|
||||
{
|
||||
Execute.Sql("DELETE FROM cmsPropertyData WHERE id NOT IN (SELECT MIN(id) FROM cmsPropertyData GROUP BY contentNodeId, versionId, propertytypeid HAVING MIN(id) IS NOT NULL)");
|
||||
//Check for MySQL
|
||||
if (Context.CurrentDatabaseProvider == DatabaseProviders.MySql)
|
||||
{
|
||||
//Use the special double nested sub query for MySQL since that is the only
|
||||
//way delete sub queries works
|
||||
SqlSyntax.GetDeleteSubquery(
|
||||
"cmsPropertyData",
|
||||
"id",
|
||||
new Sql("SELECT MIN(id) FROM cmsPropertyData GROUP BY contentNodeId, versionId, propertytypeid HAVING MIN(id) IS NOT NULL"),
|
||||
WhereInType.NotIn);
|
||||
}
|
||||
else
|
||||
{
|
||||
//NOTE: Even though the above will work for MSSQL, we are not going to execute the
|
||||
// nested delete sub query logic since it will be slower and there could be a ton of property
|
||||
// data here so needs to be as fast as possible.
|
||||
Execute.Sql("DELETE FROM cmsPropertyData WHERE id NOT IN (SELECT MIN(id) FROM cmsPropertyData GROUP BY contentNodeId, versionId, propertytypeid HAVING MIN(id) IS NOT NULL)");
|
||||
}
|
||||
|
||||
//we need to re create this index
|
||||
Delete.Index("IX_cmsPropertyData_1").OnTable("cmsPropertyData");
|
||||
|
||||
@@ -22,12 +22,23 @@
|
||||
/// <remarks>
|
||||
/// See: http://issues.umbraco.org/issue/U4-3876
|
||||
/// </remarks>
|
||||
public static Sql GetDeleteSubquery(this ISqlSyntaxProvider sqlProvider, string tableName, string columnName, Sql subQuery)
|
||||
public static Sql GetDeleteSubquery(this ISqlSyntaxProvider sqlProvider, string tableName, string columnName, Sql subQuery, WhereInType whereInType = WhereInType.In)
|
||||
{
|
||||
return new Sql(string.Format(@"DELETE FROM {0} WHERE {1} IN (SELECT {1} FROM ({2}) x)",
|
||||
|
||||
return
|
||||
new Sql(string.Format(
|
||||
whereInType == WhereInType.In
|
||||
? @"DELETE FROM {0} WHERE {1} IN (SELECT {1} FROM ({2}) x)"
|
||||
: @"DELETE FROM {0} WHERE {1} NOT IN (SELECT {1} FROM ({2}) x)",
|
||||
sqlProvider.GetQuotedTableName(tableName),
|
||||
sqlProvider.GetQuotedColumnName(columnName),
|
||||
subQuery.SQL), subQuery.Arguments);
|
||||
}
|
||||
}
|
||||
|
||||
internal enum WhereInType
|
||||
{
|
||||
In,
|
||||
NotIn
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user