My executed SQL query is as follows:
update elements E
set E.END_I = (select n.node_num
from nodes N
where abs(E.X_I - N.XI) < 0.001 and
abs(E.Y_I - N.YI) < 0.001 and
abs(E.Z_I - N.ZI) < 0.001
)
It takes about 24 seconds to complete, I read about troubleshooting firebird. Why is my database query slow? He instructs to create indexes for related fields in the table, and I added reduction / increase indexes for the XI, YI, ZI fields in both Nodes and Elements tables. But still, the performance is very slow, there are 6,677 rows in the database, and I use FlameRobin as an SQL editor.
The interesting thing: as shown in the Firebird troubleshooting guide, which has
If you see a NATURAL plan against a large table, you have found a Problem
this error is described as a bad case and a source of slowdown, the recommended solution is to create decreasing indices for related fields. But in my case, even after defining the indexes, it seems that I still suffer from this PLAN (N NATURAL), PLAN (E NATURAL), which is reported at the output of Flamerobin, as shown below.
How can I rule this out?
Preparing query: update elements E set E.END_I = (select n.node_num from nodes N
where abs(E.X_I-N.XI)<0.001 and abs(E.Y_I - N.YI)<0.001 and abs(E.Z_I-N.ZI)<0.001 )
Prepare time: 0.004s
PLAN (N NATURAL)
PLAN (E NATURAL)
Executing...
Done.
108818273 fetches, 79227 marks, 4050 reads, 9380 writes.
0 inserts, 6677 updates, 0 deletes, 0 index, 14549183 seq.
Delta memory: 212 bytes.
ELEMENTS: 6677 updates.
6677 rows affected directly.
Total execution time: 24.038s
Script execution finished.
CREATE DESCENDING INDEX IDX_ELEMENTS1 ON ELEMENTS (Z_I);
CREATE DESCENDING INDEX IDX_XI ON ELEMENTS (X_I);
CREATE DESCENDING INDEX IDX_YI ON ELEMENTS (Y_I);
GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE
ON ELEMENTS TO SYSDBA WITH GRANT OPTION;
CREATE DESCENDING INDEX IDX_NODES1_XI ON NODES (XI);
CREATE DESCENDING INDEX IDX_NODES1_YI ON NODES (YI);
CREATE DESCENDING INDEX IDX_NODES1_ZI ON NODES (ZI);
GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE
ON NODES TO SYSDBA WITH GRANT OPTION;