Requirement: There are about 1 million user records in the user table. now we want to determine whether the user is an old user or a new user based on the create_time field (user_typenew) 1. new users: within two weeks of registration, 14 (inclusive) days. 2. old User: register two... requirement description:
There are about 1 million user records in the user table. now, based on the registration time (create_time) field,
Determine whether the user is an old user or a new user (user_type new old user)
1. new users: within two weeks of registration, 14 (inclusive) days.
2. old users: registered for more than two weeks, more than 14 (not included) days.
My ideas are as follows:
Because ECShop is not a pure OOP framework, I plan to create a crontab directory in the root directory.
Create a new user. php
In user. php, the total number of records in the entire table is counted first.
Then, 100 data records are retrieved by page and the data in the entire table is updated cyclically.
When querying, the where condition filters data from old users.
That is to say, where is always user_type = 'new'. the whole table
The default value is new.
The problem is that there are 1 million records in the table. I am afraid that when I execute my PHP script
What should I do if the cyclic database check will drag the MySQL database down?
1 million data entries per page, that is, 100 million pages. how can this problem be solved?
Is the idea of for loop reliable?
Reply content:
Requirement description:
There are about 1 million user records in the user table. now, based on the registration time (create_time) field,
Determine whether the user is an old user or a new user (user_type new old user)
1. new users: within two weeks of registration, 14 (inclusive) days.
2. old users: registered for more than two weeks, more than 14 (not included) days.
My ideas are as follows:
Because ECShop is not a pure OOP framework, I plan to create a crontab directory in the root directory.
Create a new user. php
In user. php, the total number of records in the entire table is counted first.
Then, 100 data records are retrieved by page and the data in the entire table is updated cyclically.
When querying, the where condition filters data from old users.
That is to say, where is always user_type = 'new'. the whole table
The default value is new.
The problem is that there are 1 million records in the table. I am afraid that when I execute my PHP script
What should I do if the cyclic database check will drag the MySQL database down?
1 million data entries per page, that is, 100 million pages. how can this problem be solved?
Is the idea of for loop reliable?
I don't think we need to worry about it. I 'd better analyze the requirements first. what is the difference between old users and new users? Whether batch operations are involved at the same time (for example, sending short messages to the old user group is a batch operation, but a specific offer must be used by the current user as the old user, but not a batch operation ).
In many cases, this new and old user only shows the distinction, and there is no essential change, or it is always applied to the current consumer. at this time, you do not need to add a user_type field, determine whether the current user's create_time-time () is greater than 142460*60 is enough.
If you do not need this function, pay attention to the details:
1-the first update is for all data. you can execute an update statement in the database in the morning (please confirm the statement again and again ), it is much faster than you think.
2-regular update: note that you only need to check the user_type = new and create_time <... each time, instead of all users, so there is no performance problem. Can I register 0.1 million people in the last 14 days? The user_type and create_time fields should be indexed, which is also required to improve efficiency.
Update the statement in batches based on the creation time. once a statement is executed, it can be periodically executed on a daily basis,
Current time-(creation time + 86400*14) <0 indicates the new user
UPDATE user SET user_type = 'old' WHERE (unix_timestamp (now ()-(create_time + 86400*14) <0;
You can evaluate your database increment, because you can change it to an old user every day, so that the filtered data size will be greatly reduced.
Add an index to create_time of the user table (the index field must be placed on the left of where). run the following SQL statement,
UPDATE user SET user_type = 'old' WHERE create_time < date_sub(curdate(),interval 14 day)
Execute the command at every day (truncate). there are not many 1 million pieces of data.