After experiencing sluggish DB Writer behaviour, I have created a simple workflow to test the speed at which a table is written into an MySQL database. The process is very simple. It reads a table from a DB and then writes back a copy of the table.
I have tried both the MySQL Connector and the DB Connector. Here are the processes.
I just ran a test outside of Knime with the database tool DBeaver, doing the same operation (adding the 2200 rows from the CSV file to the MySQL table). It took the same time than in Knime: 25 rows per second.
So, there seems to be an issue here with filling up a / my database table with records from an external data source. I am not a database expert so I did some googling. It seems that there are slow and fast ways of getting your external data into a database table. I will need to check this out further.
I ran the same test with a different database tool (Sequel Pro), where the import of 2200 rows into the MySQL table only took 3 seconds!
Hence it seems there are big performance differences in the way these tools (Knime, DBeaver, Sequel Pro, etc.) write data into a MySQL table.
The solution when using Knime would be to use a âDB SQL Executorâ node that runs whatever query Sequel Pro is running in the background to get the data into the database. Could that work?
[UPDATE: SEE WARNING BELOW by user âbeginnerâ]
Use the âDB Loaderâ node instead of the âDB Writerâ node. With âDB Loaderâ, writing the 2200 lines to the MySQL table took less than a second.
I would be extremely careful using the loader with MySQL:
Most databases do not perform data checks when loading the data into the table which might lead to a corrupt data table . The node does some preliminary checks such as checking that the column order and column names are compatible. However it does not check the column type compatibility. So before using this node please make sure that the column types of the KNIME columns and the database columns are compatible.
And MySQL is known to do weird stuff with coercing data types so they fit. IMHO this is not a solution as 25 rows / second tells me there simply is something wrong with the database. Be it configuration or broken indexes. I would rather fix that than use this dangerous crutch.
InnoDB doesnât cope well with ârandomâ primary keys. Try a sequential key or auto-increment
Whatâs the primary key of that table? That alone could explain the issue. Again this is for sure not a KNIME issue but a huge red flag that something is off with your DB.
Was just one of many possible reasons. 25 rows per second simply is too slow so something weird must be going on and the fact itâs fast with the loader tells you itâs not your hardware. Another option are constraints / indexes as loader deactivates these.