U4-3876 - MySQL cmsContentXml Migration Error on 7.0.1 Upgrade

Created by Brian Powell 16 Dec 2013, 04:56:32 Updated by Shannon Deminick 08 Jan 2014, 23:33:12

Umbraco 7.0.1 introduced a new migration error for MySQL users.

The query to clean up the cmsContentXml table fails to run on MySQL. The query is: DELETE FROM cmsContentXml WHERE nodeId IN (SELECT DISTINCT cmsContentXml.nodeId FROM cmsContentXml INNER JOIN umbracoNode ON cmsContentXml.nodeId = umbracoNode.id WHERE nodeObjectType = 'B796F64C-1F99-4FFB-B886-4BF4BC011A9C' AND path like '%-21%')

MySQL throws error: #1093 - You can't specify target table 'cmsContentXml' for update in FROM clause. MySQL won't let you modify a table if you're doing a SELECT on it at the same time.

The query comes from Umbraco.Web\Strategies\Migrations\ClearMediaXmlCacheForDeletedItemsAfterUpgrade.cs.

Comments

Brian Powell 16 Dec 2013, 05:37:06

For MySQL, collapsing the DELETE query to eliminate the subquery gets things working. I tested this query on MySQL 5.5: DELETE cmsContentXml.* FROM cmsContentXml INNER JOIN umbracoNode ON cmsContentXml.nodeId = umbracoNode.id WHERE nodeObjectType = 'B796F64C-1F99-4FFB-B886-4BF4BC011A9C' AND path like '%-21%'

I haven't tested on MSSQL, but I presume it should work there.


Brian Powell 16 Dec 2013, 17:52:09

I tested the fix on MySQL and it works there. I don't have a MSSQL instance to test.

I submitted Pull Request 271 with my fix. https://github.com/umbraco/Umbraco-CMS/pull/271


Shannon Deminick 17 Dec 2013, 00:46:19

Thanks! I'll have to look at how we can get this working consistently across both platforms, unfortunately that query doesn't work with MSSQL :(


Shannon Deminick 17 Dec 2013, 00:48:26

Can you give this a try on MySQL:

Delete a 
from cmsContentXml a
INNER JOIN umbracoNode b
on  a.nodeId = b.id
WHERE nodeObjectType = 'B796F64C-1F99-4FFB-B886-4BF4BC011A9C' AND path like '%-21%'

That works on MSSQL


Shannon Deminick 17 Dec 2013, 00:52:35

FYI We have this same issue in other places:

ContentService.RebuildXmlStructures MediaService.RebuildXmlStructures


Brian Powell 17 Dec 2013, 00:52:51

@Shannon: In that case, maybe the best option is to check with DBMS is in use and run whichever query is appropriate for that type? It seemed like there were limited other options for MySQL and they were all pretty kludgy.


Brian Powell 17 Dec 2013, 00:56:50

@Shannon: Your query ran fine on MySQL.


Shannon Deminick 17 Dec 2013, 00:59:24

awesome, will update the other queries that have sub queries. thanks for your help (will close the PR)


Shannon Deminick 17 Dec 2013, 02:51:10

I'll also need to fix this up in my new member service changes


Shannon Deminick 08 Jan 2014, 08:15:29

Arghh! unfortunately that query doesn't work with sqlce! I have MySql installed now so will see what works on all of them.


Shannon Deminick 08 Jan 2014, 08:18:10

strangely i cannot get that to work in mysql either


Shannon Deminick 08 Jan 2014, 08:21:37

haha... apparently you can just trick mysql :) see: http://stackoverflow.com/questions/4471277/mysql-delete-from-with-subquery-as-condition with the +30 answer


Shannon Deminick 08 Jan 2014, 09:02:52

Ok, that query works on all 3 servers:

DELETE FROM cmsContentXml WHERE nodeId IN
	(SELECT nodeId FROM (SELECT DISTINCT cmsContentXml.nodeId FROM cmsContentXml 
	INNER JOIN umbracoNode ON cmsContentXml.nodeId = umbracoNode.id
	WHERE nodeObjectType = 'B796F64C-1F99-4FFB-B886-4BF4BC011A9C' AND [path] LIKE '%-21%') x)

of course for mysql you need to change the [path] to be path. Now to update the rest of the places this query type is used.


Priority: Normal

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted: Pull request

Affected versions: 6.2.0, 7.0.1

Due in version: 6.2.0, 7.0.2

Sprint:

Story Points:

Cycle: