Home > Backend Development > PHP Tutorial > How does mysql optimize a sql statement with a large amount of data and two tables need to be queried?

How does mysql optimize a sql statement with a large amount of data and two tables need to be queried?

WBOY
Release: 2016-08-26 10:28:22
Original
1256 people have browsed it

Two tables A has 2000 entries and B has 20 million entries
select a.xxx,b.xxx,b.xxxx, from A as a left join b as b on a.id = b.bid where a.xx = 0 and a.xxx != 0;

Reply content:

Two tables A has 2000 entries and B has 20 million entries
select a.xxx,b.xxx,b.xxxx, from A as a left join b as b on a.id = b.bid where a.xx = 0 and a.xxx != 0;

  1. Check in pages, don’t fetch a large amount of data at once

  2. The two fields of b to be checked for redundancy are in table a, so there is no need to join

  3. It must be cached, otherwise the database will definitely not be able to support it

  4. When the amount of data reaches tens of millions, you need to consider horizontal splitting

First of all, I am not a back-end person, so I can only tell you what I know

I don’t know if the tool can see the execution plan. If you can see the execution plan, look at the execution process. Which process generates larger data depends on whether it can be optimized

I also know that adding indexes should be able to optimize it

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template