Will it be faster for JAVA to check 5 sql with 5 threads than 5 sql with 1 thread?

Project background: the intranet OLAP application, specifically, is a variety of statistical charts for leaders to see. The project concurrency is small, so multiple threads can be used for a single request. The bottleneck is that the statistics of SQL is too slow (postgresql used)

problem description: now there are 5 slow sql, we want to optimize performance. Scenario 1 is that the web server sends a single-thread serial request to the database to check 5 sql,. Scenario 2 is that the web server has 5 threads to send requests to the database to check 5 sql.

question: ignoring the network IO delay saved by solution 2, can it be faster for scenario 2 to check 5 sql?

my understanding is that option 2 can"t be faster. The reason is:

the slow part of the database is the disk IO,. For the database, one connection to check 5 sql or 5 connections to check 5 sql should always be serially scanned 5 times, which should not be optimized?
is this understood correctly? Will 5 threads be faster?

Mar.17,2021

you can try it. The result of my experiment is that plan 2 is fast.
Scheme 1 has five sql series, and the postgre server does not make full use of the multi-core advantage, so the speed is slow.
scenario 2 concurrent 5 sql, is equivalent to 5 connections. Postgre server takes advantage of multi-core and is fast.

but you have a point. I didn't test the results you understand, indicating that disk IO is not the key to speed.


I want to know database design and sql and data volume

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bc980d-2fec8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bc980d-2fec8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?