I'm trying to represent in a UML diagram the following:
What I'm trying to explain with the diagram is that the program will do a fetch in the table using three variables: col1val, col2val and col3val; & then it will return variable col4val.
However, this is supposed to be a hierarchical fetch (not sure about the terminology), which means that it should first look up for all the columns at the same time:
SELECT col4 FROM Table WHERE col1 = col1val AND col2 = col2val AND col3 = col3val;
If it's successful, the program should leave the section and stop fetching. However, if the program fails to do the fetch, then it will try again, but adding the condition col1val IS NULL
.
SELECT col4 FROM Table WHERE col1 IS NULL AND col2 = col2val AND col3 = col3val;
Like that as many times and fields as possible. If the program ends up finding nothing after the last iteration, we now retrieve error message
.
From the diagram, the first thing I would like to avoid is to repeat:
Because it is exactly the same in all instances. I'm only nullifying fields.
I explored the option of building an IFs "pyramid", but I need to adjust the diagram with certain frequency, so repositioning the alt/if section every time takes too much.
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `Table` ADD INDEX `table_idx_col1_col1v_col2_col2v_col3_col3v` (`col1`,`col1val`,`col2`,`col2val`,`col3`,`col3val`);
SELECT
Table.col4
FROM
Table
WHERE
Table.col1 = Table.col1val
AND Table.col2 = Table.col2val
AND Table.col3 = Table.col3val