【问题标题】:memsql multi-table delete, is it possible?memsql多表删除,可以吗?
【发布时间】:2016-10-03 13:36:34
【问题描述】:

MEMSQL!我想删除一个表中的记录,该记录在另一个表的多个字段中具有匹配项。这可能吗?

我将使用的 MySql 查询可能类似于:

delete from t1 used t1,t2 where t1.f1=t2.f1 and t1.f2=t2.f2

或

delete t1 from t1,t2 where...

根据http://docs.memsql.com/docs/delete:

MemSQL 还不完全支持多表 DELETE 语句。 WHERE 子句中的子查询是唯一的多表 DELETE 允许。

我可以在删除 where 子句中使用多个条件而不使用 concat 等吗?

附:对不起我糟糕的英语

【问题讨论】:

标签: mysql sql-delete singlestore


【解决方案1】:

试试这样的:

delete from t1 where exists (select 1 from t2 where t1.f1=t2.f1 and t1.f2=t2.f2)

【讨论】:

  • 谢谢回答!对于选择它有效。但是 delete 得到错误“'correlated subselect that can't be translate and not match on shard keys' is not supported by memsql Distributed”
  • 如果连接是跨分片的,MemSQL 目前对这些查询形状的支持有限。如果您可以使 t1 和 t2 的分片键包含 (f1, f2) 那么它应该可以工作。另一种解决方案是使 t1 和 t2 中的任何一个成为参考表。
【解决方案2】:

我在尝试从另一个表更新一个表的某些字段时遇到了同样的问题。

问题是 MemSQL Distributed 不支持无法转换且与分片键不匹配的相关子选择 所以我的解决方案是创建一个选择查询来生成更新查询,然后运行它们。这是一个简化的生成器查询:

select concat('update table1 set t1_code=\'',t2_code,
    '\',t1_url=\'',t2_url,
    '\',t1_width=\'',t2_width,
    '\' where t1.id=',t2.id,';') query
from t1
inner join t2 on t2.id=t1.id;

为需要更新的每一行生成更新查询,用;分隔。

生成删除将更加容易 - 您只需选择要删除的 id 并生成查询delete from t1 where id in (-the list of ids that was selected for deletion-)

这是我对这个 memsql 限制的解决方法。

【讨论】:

    猜你喜欢
    • 2017-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多