Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 9479:3a683b2476e2
mod_storage_sql: Workaround MySQL not supporting LIMIT subquery in archive truncate operations, fixes #1200
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 11 Oct 2018 18:20:09 +0100 |
parent | 9459:6c279302fff4 |
child | 9492:c03c60a2dede |
comparison
equal
deleted
inserted
replaced
9478:bd178ed0459b | 9479:3a683b2476e2 |
---|---|
396 WHERE %s | 396 WHERE %s |
397 ORDER BY "sort_id" %s | 397 ORDER BY "sort_id" %s |
398 LIMIT %s OFFSET ?; | 398 LIMIT %s OFFSET ?; |
399 ]]; | 399 ]]; |
400 unlimited = "-1"; | 400 unlimited = "-1"; |
401 elseif engine.params.driver == "MySQL" then | |
402 sql_query = [[ | |
403 DELETE result FROM prosodyarchive AS result JOIN ( | |
404 SELECT sort_id FROM prosodyarchive | |
405 WHERE %s | |
406 ORDER BY "sort_id" %s | |
407 LIMIT %s OFFSET ? | |
408 ) AS limiter on result.sort_id = limiter.sort_id;]]; | |
409 unlimited = "18446744073709551615"; | |
401 else | 410 else |
402 sql_query = [[ | 411 sql_query = [[ |
403 DELETE FROM "prosodyarchive" | 412 DELETE FROM "prosodyarchive" |
404 WHERE "sort_id" IN ( | 413 WHERE "sort_id" IN ( |
405 SELECT "sort_id" FROM "prosodyarchive" | 414 SELECT "sort_id" FROM "prosodyarchive" |
406 WHERE %s | 415 WHERE %s |
407 ORDER BY "sort_id" %s | 416 ORDER BY "sort_id" %s |
408 LIMIT %s OFFSET ? | 417 LIMIT %s OFFSET ? |
409 );]]; | 418 );]]; |
410 if engine.params.driver == "MySQL" then | |
411 unlimited = "18446744073709551615"; | |
412 end | |
413 end | 419 end |
414 sql_query = string.format(sql_query, t_concat(where, " AND "), | 420 sql_query = string.format(sql_query, t_concat(where, " AND "), |
415 query.reverse and "ASC" or "DESC", unlimited); | 421 query.reverse and "ASC" or "DESC", unlimited); |
416 end | 422 end |
417 return engine:delete(sql_query, unpack(args)); | 423 return engine:delete(sql_query, unpack(args)); |