From 0d84b5f3b4e66ff24a63caa91ce34433d5474cb9 Mon Sep 17 00:00:00 2001 From: Martin Ambrus Date: Fri, 27 Oct 2017 19:36:27 +0200 Subject: [PATCH] fix: MySQL variables can't be used inside IN statements as such So, if we want to do something like "WHERE abc IN ( @ids )", where @ids would contain a string of "1,2,3", we can't and would need to use FIND_IN_SET() function instead. --- var/db/datagen-oasis-troops-regen.sql | 154 ++++++++++++++++++++++++-- 1 file changed, 143 insertions(+), 11 deletions(-) diff --git a/var/db/datagen-oasis-troops-regen.sql b/var/db/datagen-oasis-troops-regen.sql index 6113cbcb..84b980db 100644 --- a/var/db/datagen-oasis-troops-regen.sql +++ b/var/db/datagen-oasis-troops-regen.sql @@ -59,7 +59,19 @@ UPDATE %PREFIX%odata WHERE @natureRegTime = -1 AND - conqured IN ( @village ); + ( + ( + -- should we have a list of IDs, we need to use FIND_IN_SET + LOCATE(",", @village) > 0 + AND + FIND_IN_SET(conqured, @village) + ) + OR + ( + -- for a single ID, we use a simple condition which can definitely use an index as well + conqured = @village + ) + ); -- --------------------------------------------- -- remove past reports (conquered > unoccupied) @@ -68,7 +80,19 @@ DELETE FROM %PREFIX%ndata WHERE @natureRegTime = -1 AND - toWref IN ( @village ); + ( + ( + -- should we have a list of IDs, we need to use FIND_IN_SET + LOCATE(",", @village) > 0 + AND + FIND_IN_SET(toWref, @village) + ) + OR + ( + -- for a single ID, we use a simple condition which can definitely use an index as well + toWref = @village + ) + ); -- ---------------------------------------------------------------- @@ -81,7 +105,19 @@ SET WHERE @natureRegTime > -1 AND - wref IN ( @village ); + ( + ( + -- should we have a list of IDs, we need to use FIND_IN_SET + LOCATE(",", @village) > 0 + AND + FIND_IN_SET(wref, @village) + ) + OR + ( + -- for a single ID, we use a simple condition which can definitely use an index as well + wref = @village + ) + ); -- ----------------------------------------------------------------------- @@ -116,7 +152,19 @@ UPDATE %PREFIX%units u ( @village > -1 AND - vref = @village + ( + ( + -- should we have a list of IDs, we need to use FIND_IN_SET + LOCATE(",", @village) > 0 + AND + FIND_IN_SET(vref, @village) + ) + OR + ( + -- for a single ID, we use a simple condition which can definitely use an index as well + vref = @village + ) + ) ) ) AND @@ -172,7 +220,19 @@ UPDATE %PREFIX%units u ( @village > -1 AND - vref = @village + ( + ( + -- should we have a list of IDs, we need to use FIND_IN_SET + LOCATE(",", @village) > 0 + AND + FIND_IN_SET(vref, @village) + ) + OR + ( + -- for a single ID, we use a simple condition which can definitely use an index as well + vref = @village + ) + ) ) ) AND @@ -226,7 +286,19 @@ UPDATE %PREFIX%units u ( @village > -1 AND - vref = @village + ( + ( + -- should we have a list of IDs, we need to use FIND_IN_SET + LOCATE(",", @village) > 0 + AND + FIND_IN_SET(vref, @village) + ) + OR + ( + -- for a single ID, we use a simple condition which can definitely use an index as well + vref = @village + ) + ) ) ) AND u31 <= ( @@ -278,7 +350,19 @@ UPDATE %PREFIX%units u ( @village > -1 AND - vref = @village + ( + ( + -- should we have a list of IDs, we need to use FIND_IN_SET + LOCATE(",", @village) > 0 + AND + FIND_IN_SET(vref, @village) + ) + OR + ( + -- for a single ID, we use a simple condition which can definitely use an index as well + vref = @village + ) + ) ) ) AND u31 <= ( @@ -329,7 +413,19 @@ UPDATE %PREFIX%units u ( @village > -1 AND - vref = @village + ( + ( + -- should we have a list of IDs, we need to use FIND_IN_SET + LOCATE(",", @village) > 0 + AND + FIND_IN_SET(vref, @village) + ) + OR + ( + -- for a single ID, we use a simple condition which can definitely use an index as well + vref = @village + ) + ) ) ) AND u31 <= ( @@ -381,7 +477,19 @@ UPDATE %PREFIX%units u ( @village > -1 AND - vref = @village + ( + ( + -- should we have a list of IDs, we need to use FIND_IN_SET + LOCATE(",", @village) > 0 + AND + FIND_IN_SET(vref, @village) + ) + OR + ( + -- for a single ID, we use a simple condition which can definitely use an index as well + vref = @village + ) + ) ) ) AND u31 <= ( @@ -434,7 +542,19 @@ UPDATE %PREFIX%units u ( @village > -1 AND - vref = @village + ( + ( + -- should we have a list of IDs, we need to use FIND_IN_SET + LOCATE(",", @village) > 0 + AND + FIND_IN_SET(vref, @village) + ) + OR + ( + -- for a single ID, we use a simple condition which can definitely use an index as well + vref = @village + ) + ) ) ) AND u31 <= ( @@ -495,7 +615,19 @@ UPDATE %PREFIX%units u ( @village > -1 AND - vref = @village + ( + ( + -- should we have a list of IDs, we need to use FIND_IN_SET + LOCATE(",", @village) > 0 + AND + FIND_IN_SET(vref, @village) + ) + OR + ( + -- for a single ID, we use a simple condition which can definitely use an index as well + vref = @village + ) + ) ) ) AND u31 <= (