Question: Edit : I need the program to do computational faster, the update process is needed to be real time (calculating 100.000 to 200.000 records for about 0-5 seconds), this process will be doing in multi threading (about 2-8 thread)

---

I will create program that will update data in database. The update process will be triggered if I do insert data in table. The update process will computational costly. This is the idea of my update process :

1. I will have 3 tables (A,B,C) and each of it will have data aroud 100.000-200.000 records
2. I will have table D to save table A, B, C record count
3. I will have table E to save table A, B, C, D calculation, the calculation including multiplication, division and log base 2
4. I will insert data to table A, B, C and after that data in table D and E must be updated
5. This process can be repeated 3-5 times in every update

Which one is computationally faster, doing update programmatically or using trigger?

Answer: 
Computational cycles in your database server are a scarce resource. You can have as many server instances running your Java program as you can afford, and as your application scales up (adds users, for example) you can distribute the computationally intensive operation to multiple servers.

If you perform the computationally expensive stuff on your MySQL server, you are deciding to do it all on a central machine.

Plus, in my experience, it is easier to unit test and maintain Java code than it is to do the same for trigger / stored procedure code.

That being said, MySQL's floating-point math operations (log, multiplication) exploit the server's math instruction set and are reasonably efficient.
> 
> I will have 3 tables (A,B,C) and each of it will have data aroud
>  100.000-200.000 records
> 
> 
> 

This is a trivially small database.

```
I will have table D to save table A, B, C record count

```

Are you keeping a history of records in each on a particular datetime? That's the only reason to do this.

```
I will have table E to save table A, B, C, D calculation, the calculation including multiplication, division and log base 2

```

Easy stuff.

```
I will insert data to table A, B, C and after that data in table D and E must be updated

```

Making all of this a single unit of work is the important thing. I hope you're making them a transaction.

This process can be repeated 3-5 times in every update Which one is faster, doing update programmatically or using trigger?

I would think database - stored procedure and trigger first. Especially if there are a lot of UPDATEs.

Are the three sources of data A, B, and C independent? If I INSERT into A, do I execute the calculations for D and E? Likewise for B and C? Could you potentially have a great deal of traffic if all three have records INSERTed in a short period of time?