Bug #99486 Too many work doing in class construct function in Buf_fetch_normal
Submitted: 8 May 2020 10:19 Modified: 9 May 2020 7:58
Reporter: chen zongzhi (OCA) Email Updates:
Status: Not a Bug Impact on me:
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:8.0.20 OS:Any
Assigned to: CPU Architecture:Any

[8 May 2020 10:19] chen zongzhi
In the new code, InnoDB refactor the long function buf_page_get_gen()

However, I find in the constructor function of Buf_fetch_normal, it call dberr_t Buf_fetch_normal::get(buf_block_t *&block);

we know that in cpp code coding paradigm, it better only doing some light work in constructor function, such as assign variables default value. Because the constructor don't return the result, and if the constructor fail, the object it construct is NULL. 
so It's better to put the large function outside the constructor function, add a function call Init().  

struct Buf_fetch_normal : public Buf_fetch<Buf_fetch_normal> {
  Buf_fetch_normal(const page_id_t &page_id, const page_size_t &page_size)
      : Buf_fetch(page_id, page_size) {}

  dberr_t get(buf_block_t *&block);

How to repeat:
read the code
[8 May 2020 13:27] MySQL Verification Team
Hi Mr. zongzhi,

Thank you for your bug report.

I fully understand what you are writing about and I have stuck to that paradigm in my own C++ code.

However, this is not the only place in our code where constructor  sets the object to NULL. What you asking for would necessitate a very large redesign of very large part of our code, with the sole objective of maintaining the object purity. That would be a huge undertaking without adding any feature, or fixing a bug or improving performance.

However,  I will inform our Development of your code purity request.
[9 May 2020 2:52] Sunny Bains
I think the bug reporter is confused. There is no get() call from within the constructor.
[9 May 2020 7:58] chen zongzhi
Yes, Sunny.
That is my mistake..
You are right.