Logically, the more logic we added to the query(like number of joins, subqueries...) which increases the complexity, the more RDBMS(like MySQL) will process, therefore it will take more time to process, am I right?
Yes and no.
Firstly, this applies to any system, regardless if it's an RDBMS, NoSQL, NewSQL, or otherwise. The more operations that any system needs to process, the more work there is being performed. The overhead for these operations are generally very minimal.
But as Akina mentioned in the comments, the operations may reduce the amount of data (e.g. from JOIN
, GROUP BY
, WHERE
and HAVING
clauses, etc.) that needs to be subsequently processed and returned. The savings on data reduction can significantly improve total execution time.
An example of this, where an RDBMS may outperform a NoSQL database because of the additional operational complexity, is with two tables that have a one-to-many relationship, and a few other additionally related tables. If the many table is huge, but you write a query that only returns a single entity from the one side joined to its related many records, the JOIN
will reduce the data significantly before any further processing is needed and returns much less data. And if you don't necessarily need the additional data from the other related tables, you wouldn't have to JOIN
them in. Conversely a NoSQL database would pre-stage the data fully joined from all of the aforementioned tables already, resulting in a single exploded out table that would likely require more Memory to load off Disk, and more work to search, for just the subset of data you care about.
With a properly designed and architected database, with the correct indexes implemented, all of the aforementioned operations should happen in negligible time (milliseconds or less).
INDEX
. A "point query" with a good index takes about the same amount of time on a billion-row table as on a 10-row table. Etc, etc.