Bug #118000 Innodb blob partial update has some redundant code
Submitted: 17 Apr 3:51 Modified: 8 Jul 4:54
Reporter: Wang Zhengmao (OCA) Email Updates:
Status: Need Feedback Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S4 (Feature request)
Version:8.0.42 OS:Any
Assigned to: CPU Architecture:Any

[17 Apr 3:51] Wang Zhengmao
Description:
Some code in lob::btr_store_big_rec_extern_fields function is redundant. 

If an update of blob or zlob can satisfy the condition of ```(op == lob::OPCODE_UPDATE && upd != nullptr && blobref.is_big(rec_block->page.size) && can_do_partial_update)```, there is no need to recheck ```upd->is_partially_updated(field_no)```.

Because when can_do_partial_update is true, it implies current field is partially updated.

How to repeat:
Now take a look at the blob update process.
First, it will try optimistic update. But some fields need to be stored in off-page, optimistic update failed and return DB_OVERFLOW error.
Second, it will try pessimistic update. It calls lob::mark_not_partially_updatable to make a tag on those non-virtual fields which is not partially updated.
Third, when storing off-page column in InnoDB, it checks two conditions and one futher condition to decide whether to execute partial update.

The former two conditions is:
     1. Whether the first off-page type is FIL_PAGE_TYPE_LOB_FIRST or FIL_PAGE_TYPE_ZLOB_FIRST
     2. Whether the fields is set a tag to imply the fields is not partial update, which should be set in step 2 if field is not partial updated.

The futher condition is :
     1. check whether current field is partial update, which is equal to the second condition in the former conditions.

Therefore, it's no need to recheck the further condition. Do partial update directly.
[23 May 13:53] Annamalai Gurusami
The function upd_t::is_partially_updated() is the one that checks whether InnoDB received the partial update vector from the server layer.  The variable can_do_partial_update checks whether the conditions are OK at InnoDB level.  

At InnoDB level, any blob data can be partially updated (the conditions could be suitable).  But at server layer level partial updates are allowed/enabled only for JSON documents via certain functions.

Since JSON documents have a special format (which InnoDB doesn't know about), the server layer needs to determine and pass down the partial update vector, which InnoDB will use only when its own limitations are satisfied.  

Unless you can demonstrate a performance issue or a functionality issue, I would like to close this as 'Not a bug'.  If some part of the code needs more developer documentation, let me know.  I'll try to update with more details.