简体   繁体   中英

Efficient (PHP?) Filtering from MySQL with 3 Big tables

I am working on a filtering section with "large" tables and performance (for SELECT) is of great concern.

table_1 has 710,000 records and looks like this:

(PK) game_id   
param_1  
param_2  
param_3  

table_2 has 42,218,503 records and looks like this:

(PK) set_id  
value_1   
value_2    

table_3 has 56,312,204 records and looks like this:

(PK) relation_id  
game_id  
set_id  
box_1  
box_2

Inserts are not common (once a week) but Selects are (many, daily).
3 types of searches are common:

  1. By table_1 only (using param_1, param_2, param_3)
  2. By table_3 only, providing the value_1 to search for
  3. A combination of both

Each search will return 20 games at most, and I am concerned about the 3d case, where they search for both param_1, param_2 and value_1, value_2 in table_1 and table_2. I do not want to use a SELECT...JOIN because of the size of the temporal tables (between the 3 tables data is over 10 GB). I can also cache content (since it should never change) to flat files with PHP.

The routine I have been thinking about is as follows:

Step 1: SELECT the set_id

Step 2: SELECT all game_id from table_3 WHERE set_id = value from Step 1

Setp 3: Build the SELECT for table_1 WHERE game_id = values from Step 2

Ideas or comments on this approach?

(Im not on a dedicated server -yet- and tables are in the 3d Normal Form)

Just write the SQL to join in the tables as designed, DBs tend to include a few optimizations that would be difficult for an interpenetrated language like php to match.

If your query runs to slow, then look at your WHERE and make sure an index is used. If it is still slow look at the joins.... from there you can ask a more specific tuning question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM