When sql queries some basic data (infrequently changing) relationship, the relationship can be written into the table

original query
FROM
	table1 t
LEFT JOIN (
	SELECT
		regcert_id,
		count(1) AS num
	FROM
		table2
	GROUP BY
		regcert_id
) t1 ON t1.table1_id = t.id


After remodeling
SELECT
		regcert_id,
		count(1) AS num
	FROM
		table2
	GROUP BY
		regcert_id
The queried data is written to the new table, such as

the optimized statement of table2
FROM
	table1 t
LEFT JOIN table2 t1 ON t1.table1_id = t.id


Note: The premise of this transformation is that the table2 data does not change frequently. If you change it, you need to execute the corresponding script.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326178883&siteId=291194637