Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Set deletion query for improved performance. #1443

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/models/ca_sets.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,13 @@ public function delete($pb_delete_related=false, $pa_options=null, $pa_fields=nu

// quickly delete attribute values
$this->getDb()->query('
DELETE FROM ca_attribute_values WHERE attribute_id IN
(SELECT attribute_id FROM ca_attributes WHERE table_num=? and row_id IN (SELECT item_id FROM ca_set_items WHERE set_id = ?))
DELETE av.* FROM ca_attribute_values av JOIN ca_attributes a ON av.attribute_id = a.attribute_id
JOIN ca_set_items s on a.row_id = s.item_id WHERE a.table_num=? and s.set_id = ?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to use a multi-table delete then perhaps we should delete both ca_attributes and ca_attribute_values in a single query?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. On it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@collectiveaccess ah, no we cannot do this in one statement because of the foreign key constraint. (at least not without a workaround that I don't feel comfortable doing.)

', array($this->tableNum(), $this->getPrimaryKey()));

// quickly delete attributes
$this->getDb()->query('
DELETE FROM ca_attributes WHERE table_num=? and row_id IN (SELECT item_id FROM ca_set_items WHERE set_id = ?)
DELETE a.* FROM ca_attributes a JOIN ca_set_items s on a.row_id = s.item_id WHERE a.table_num=? AND s.set_id = ?
', array($this->tableNum(), $this->getPrimaryKey()));

// get list of set item ids
Expand Down