If I need to display 80 thousand records from one table in the database, and for each record, substitute a header from the second table, then how is it most practical for me to do so that there are no problems with the RAM on the server and other concerns. I would like to know by what vectors to search for information.

Here is what I can do at the moment:

$komrads = DbQuery::fetchAll("SELECT * FROM everyone_in_andorra"); foreach ($komrads as $komrad) { $vernacular = DbQuery::fetchOne("SELECT language FROM kgb_list WHERE komradid = '".$komrad['id']."' LIMIT 1"); if (!$vernacular) { echo $komrad['id']."<br> Не владеет языками"; } else { echo $komrad['name']." - ".$vernacular['language']."<br>"; } } 
  • Of course, this should be done in one request, something like select id, name, (select language from kgb_list where komradid=A.id limit 1) as lang from everyone_in_andorra A - Mike
  • @Mike, but for не владеет языками second request? - avp
  • @avp second is not needed. If the string "lang = NULL", i.e. empty value means not owning. - Mike
  • @AndreyTalanin here join is poorly applicable, because it is necessary to choose one record (limit 1) from several. This is normally quite difficult to implement with join, especially on MySQL - Mike

1 answer 1

1) SELECT * FROM everyone_in_andorra is so bad. You definitely need all the records, if yes, specify them all the same, it will be better.

2) Pagination on the table should be the easiest way (and it’s not very good) limit offset , of course the usual where id < ? and id > ? would be better to behave where id < ? and id > ? where id < ? and id > ?

3) Join in principle is appropriate here but bad in large tables. You can use the link by id using IN - there are other options.

4) 80,000 - not at all a lot should not directly kill the system, but of course in the hands of the coder

5) Do not forget of course about the indexes in the tables is important.