I
I
Ivan Kolesnik2016-06-23 17:27:00
MySQL
Ivan Kolesnik, 2016-06-23 17:27:00

Complex fetch from MySQL?

Such a task. There is a kind of ... calculator. In it, roughly speaking, 200 positions. Calculator for calculating services for a certain type of work. Prices for services should be generated automatically, according to the data entered by the register. users. That is, after registration, they get the opportunity to fill in "their" calculator, which is saved in a separate table (each user has their own table with values). There is a cron that every night, in theory, will get all-all-all values ​​from the database, from each table, for each category (i.e., each table can contain 200 records, and if there are at least ten users, this is already 2000 requests) just for the sake of choosing the highest value for a particular category. General view of such tables
------------------------------
| id | category_id | price |
...
| 234 | 156 | 52 |
| 235 | 157 | 12 |
...
--------------------
It turns out just an unrealistic load on the server. And among all the tables, of which there will be thousands, you need to select the maximum and minimum value for a specific category_id. Hope I explained clearly.
So far, the method is just hellish - I select all the tables with SHOW, go through them with foreachs, whils, pull out all the values, save them all in a separate array, and so on as many times as there are in the table database. As a result, two users took me about 185 ms and about a thousand requests passed. What to do? (
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DTX, 2016-06-23
@DirecTwiX

Not very clear.

  1. Why not merge all tables into one by adding one column for a feature?
  2. All users can be processed in one request
  3. Instead of executing queries in a loop over tables (and indeed any queries in a loop), it is better to collect the query text dynamically and execute it once

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question