Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

SQL Optimisation Commit for zzzzsys_tab

Questions related to using nuBuilder Forte.
Post Reply
apmuthu
Posts: 249
Joined: Sun Dec 06, 2020 6:50 am
Location: Chennai, India, Singapore

SQL Optimisation Commit for zzzzsys_tab

Unread post by apmuthu »

The effective change in the recent commit apart from a slate of whitespace changes have changed the following SQL:

Code: Select all

SELECT * 
        FROM zzzzsys_tab 
        INNER JOIN zzzzsys_object ON sob_all_zzzzsys_form_id = syt_zzzzsys_form_id
        WHERE syt_zzzzsys_form_id = '$i'
        GROUP BY syt_zzzzsys_form_id, syt_title
        ORDER BY syt_order;
to:

Code: Select all

SELECT DISTINCT zzzzsys_tab.*
        FROM zzzzsys_tab 
        INNER JOIN zzzzsys_object ON sob_all_zzzzsys_form_id = syt_zzzzsys_form_id
        WHERE syt_zzzzsys_form_id = '$i'
        ORDER BY syt_order;
The major change here is to restrict the resultset into keeping just one tables' fields instead of those from both but I wonder what the "ORDER by sy_order" really does since many are of the same order value.

The following may be a better bet considering optimisation:

Code: Select all

SELECT zzzzsys_tab.*
        FROM zzzzsys_tab 
        INNER JOIN zzzzsys_object ON sob_all_zzzzsys_form_id = syt_zzzzsys_form_id
        GROUP BY `zzzzsys_tab_id`, `syt_zzzzsys_form_id`
        HAVING syt_zzzzsys_form_id = '$i';
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: SQL Optimisation Commit for zzzzsys_tab

Unread post by kev1n »

apmuthu wrote: The following may be a better bet considering optimisation:

Code: Select all

SELECT zzzzsys_tab.*
        FROM zzzzsys_tab 
        INNER JOIN zzzzsys_object ON sob_all_zzzzsys_form_id = syt_zzzzsys_form_id
        GROUP BY `zzzzsys_tab_id`, `syt_zzzzsys_form_id`
        HAVING syt_zzzzsys_form_id = '$i';
This changes the Tab order since there's no ORDER BY:
order.png
tabs.png
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: SQL Optimisation Commit for zzzzsys_tab

Unread post by kev1n »

apmuthu wrote: I wonder what the "ORDER by sy_order" really does since many are of the same order value.
The SQL filters by syt_zzzzsys_form_id. One form has distinct sy_order values.
apmuthu
Posts: 249
Joined: Sun Dec 06, 2020 6:50 am
Location: Chennai, India, Singapore

Re: SQL Optimisation Commit for zzzzsys_tab

Unread post by apmuthu »

Okay. I assumed that when the order was changed, the db would get rewritten for the form_id in the desired order.
Hence the following will be in order:

Code: Select all

SELECT zzzzsys_tab.*
        FROM zzzzsys_tab
        INNER JOIN zzzzsys_object ON sob_all_zzzzsys_form_id = syt_zzzzsys_form_id
        GROUP BY `zzzzsys_tab_id`, `syt_zzzzsys_form_id`
        HAVING syt_zzzzsys_form_id = '$i'
        ORDER BY syt_order;
The use of DISTINCT is to be avoided where possible and any large table on which the query is run (with appropriate indices) will prove itself in benchmark tests.
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: SQL Optimisation Commit for zzzzsys_tab

Unread post by kev1n »

Thanks! I committed an update to my dev repo.
Post Reply