0
目前,我们有这样的代码片段:将多个删除查询修改为尽可能少的更新查询?
$this->db->where('id', $id)->delete($this->table);
$this->db->where('product_id', $id)->delete($this->clink);
$this->db->where('product_id', $id)->delete($this->tlink);
$variants = $this->db->select('id')->from($this->vlink)->where('product_id', $id)->get();
if ($variants->num_rows() !== 0) {
//turns array(array('id' => 1), array('id' => 2)) into array(1,2)
$variants = $variants->result_array();
foreach ($variants as &$v) {
$v = $v['id'];
}
$this->db->where('product_id', $id)->delete($this->vlink);
$this->db->where_in('variant_id', $variants)->delete('cart_variant_values');
$this->db->where_in('variant_id', $variants)->delete('cart_variant_images');
$this->db->where_in('variant_id', $variants)->delete('cart_variant_documents');
}
换算成这样:
delete from $this->table where id = $id
delete from $this->clink where product_id = $id
delete from $this->tlink where product_id = $id
$variants = select id from $this->vlink where product_id = $id //e.g. (1,2)
delete from $this->vlink where product_id = $id
delete from cart_variant_values where variant_id in $variants
delete from cart_variant_images where variant_id in $variants
delete from cart_variant_documents where variant_id in $variants
现在我需要修改代码,而不是删除所有的行,它设置对他们的end_date
列所有。
我知道我可以修改它。留下它与相同数量的查询,但我希望是一个更新而不是删除我可以缩减成更少的查询?