title: Does select_for_update see rows added by another select_for_update transaction after it unblocks?
body: <p>I want to create a model with ID equal to the current greatest ID for that model plus one (like auto-increment). I'm considering doing this with <code>select_for_update</code> to ensure there is no race condition for the current greatest ID, like this:</p>
  
  <pre><code>with transaction.atomic():
      greatest_id = MyModel.objects.select_for_update().order_by('id').last().id
      MyModel.objects.create(id=greatest_id + 1)
  </code></pre>
  
  <p>But I'm wondering, if two processes try to run this simultaneously, once the second one unblocks, will it see the new greatest ID inserted by the first process, or will it still see the old greatest ID?</p>
  
  <p>For example, say the current greatest ID is 10. Two processes go to create a new model. The first one locks ID 10. Then the second one blocks because 10 is locked. The first one inserts 11 and unlocks 10. Then, the second one unblocks, and now will it see the 11 inserted by the first as the greatest, or will it still see 10 because that's the row it blocked on?</p>
  
  <p>In the select_for_update <a href="https://docs.djangoproject.com/en/1.11/ref/models/querysets/#select-for-update" rel="nofollow noreferrer">docs</a>, it says:</p>
  
  <blockquote>
    <p>Usually, if another transaction has already acquired a lock on one of the selected rows, the query will block until the lock is released.</p>
  </blockquote>
  
  <p>So for my example, I'm thinking this means that the second process will rerun the query for the greatest ID once it unblocks and get 11. But I'm not certain I'm interpreting that right.</p>
  
  <p>Note: I'm using MySQL for the db.</p>