mysql-deadlock-02.diff

Toshi MARUYAMA, 2017-03-21 16:35

Download (1.31 KB)

View differences:

lib/redmine/nested_set/issue_nested_set.rb
158 158
          self.class.reorder(:id).where(:root_id => sets_to_lock).lock(lock).ids
159 159
        else
160 160
          sets_to_lock = [id, parent_id].compact
161
          self.class.reorder(:id).where("root_id IN (SELECT root_id FROM #{self.class.table_name} WHERE id IN (?))", sets_to_lock).lock.ids
161
          if Redmine::Database.postgresql?
162
            self.class.reorder(:id).
163
              where("root_id IN (SELECT root_id FROM #{self.class.table_name} WHERE id IN (?))", sets_to_lock).
164
              lock.ids
165
          else
166
            inner_join_statement = self.class.select(:root_id).where(id: sets_to_lock).distinct(:root_id).to_sql
167
            self.class.reorder(:id).
168
              joins("INNER JOIN (#{inner_join_statement}) as i2 ON #{self.class.table_name}.root_id = i2.root_id").
169
              lock.ids
170
          end
162 171
        end
163 172
      end
164 173