Avatar

2.4.24 performance comments. (General)

by Micha ⌂, Friday, April 07, 2023, 12:38 (393 days ago) @ Joe I

Hi Joe,

Base:
LEFT JOIN mlf2_read_entries AS rst ON rst.posting_id = ft.id AND rst.user_id = 0
Modified:
LEFT JOIN mlf2_read_entries AS rst ON rst.posting_id = ft.id AND IFNULL(rst.user_id, NULL) = 0

I've come across this before and it always seems bizarre, but it works.

This looks strange. In the first statement, rst.user_id is compared with zero. It is like

if (rst.user_id == 0) {
 //do something
}

In your modified statement, a second condition is added in front of the prior condition. However, the second one is identical to the condition of the first statement.

if (rst.user_id == NULL) {
  rst.user_id = NULL;
}
if (rst.user_id == 0) {
 //do something
}

I could have immediately understood that the following change would make an improvement (no further type-cast),

if (rst.user_id == NULL) {
  rst.user_id = -1;
}

However, if such a simple change works, we should change the statements...

/Micha

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences


Complete thread:

 RSS Feed of thread