Ask a question about PHP large Array de-weight

Source: Internet
Author: User
Ask a question about large arrays of PHP to go heavy
Ask a question, about PHP Large array operation, a table has millions of of the data to get the PHP array to do the redo operation:
For example: ID Gender ID Three fields, need to count the number of men and women each (there are other specific logic, not in MySQL to go Heavy)
Implementation method: ID is self-increment, each time by the ID of 5w data, get an array to do the redo operation
$count = Array (
' Male ' = = Array (
' ID 1 ' = + 1,
' ID 2 ' = + 1,
....
),
' Woman ' = ...
);
Finally see how many women and men under the identity card is to go back to the data
Problem: As the array becomes larger and heavier, the speed of de-weight is getting slower, and I don't know if there are any other solutions or optimization methods to ask, thx!
------to solve the idea----------------------
We do a test on the data you give us.
Drop table if exists play;

CREATE TABLE ' Play ' (
' id ' int (ten) unsigned not NULL auto_increment,
' Time ' int (ten) is not NULL,
' UID ' int (ten) unsigned not NULL,
' Game ' varchar (255) Not NULL,
' Channel ' varchar (255) Not NULL,
' System ' varchar (255) is not NULL,
' Screen ' varchar (255) is not NULL,
' Network ' varchar (255) is not NULL,
PRIMARY KEY (' id '),
KEY ' datetime ' (' Time ')
) CHARSET=GBK;

INSERT INTO play values
(1,1421812389,10000, ' All games-World of Warcraft-0 uniforms ', ' 360-360 leagues ', ' WIN7 ', ' 1024x768 ', ' telecom '),
(2,1421812389,10001, ' All games-World of Warcraft-1 Costumes ', ' NetEase-netease alliance ', ' XP ', ' 1366x768 ', ' unicom '),
(3,1421812389,10000, ' All games-World of Warcraft-0 uniforms ', ' 360-360 leagues ', ' WIN7 ', ' 1024x768 ', ' telecom ');

drop table if exists play_game;

CREATE TABLE Play_game (game varchar) CHARSET=GBK;

INSERT into play_game values (' All games '), (' World of Warcraft '), (' 0 uniforms '), (' 1 uniforms ');

drop table if exists play_channel;

CREATE TABLE Play_channel (channel varchar) CHARSET=GBK;

INSERT into Play_channel values (' 360 '), (' 360 Leagues '), (' NetEase '), (' NetEase Alliance ');

Select a.ID, A.time, A.uid, B.game, C.channel, A.system, A.screen, a.network from play A, play_game B, Play_channel c wher E
Find_in_set (B.game, replace (a.game, '-', ', '))
and
Find_in_set (C.channel, replace (A.channel, '-', ', '))
To get this result.

ID time UID Game Channel system Screen Network
1 1421812389 10000 All games WIN7 1024x768 Telecom
3 1421812389 10000 All games WIN7 1024x768 Telecom
1 1421812389 10000 World of Warcraft WIN7 1024x768 Telecom
3 1421812389 10000 World of Warcraft WIN7 1024x768 Telecom
1 1421812389 10000 0 service WIN7 1024x768 Telecom
3 1421812389 10000 0 service WIN7 1024x768 Telecom
1 1421812389 10000 All games 360 Federation WIN7 1024x768 Telecom
3 1421812389 10000 All games 360 Federation WIN7 1024x768 Telecom
1 1421812389 10000 World of Warcraft 360 Alliance WIN7 1024x768 Telecom
3 1421812389 10000 World of Warcraft 360 Alliance WIN7 1024x768 Telecom
1 1421812389 10000 0 Service 360 Federation WIN7 1024x768 Telecom
3 1421812389 10000 0 Service 360 Federation WIN7 1024x768 Telecom
2 1421812389 10001 All games netease XP 1366x768 unicom
2 1421812389 10001 World of Warcraft netease XP 1366x768 unicom
2 1421812389 10001 1 service netease XP 1366x768 unicom
2 1421812389 10001 All games netease Alliance XP 1366x768 Unicom
2 1421812389 10001 World of Warcraft netease Alliance XP 1366x768 Unicom
2 1421812389 10001 1 service netease Alliance XP 1366x768 Unicom

From this result, what else is not SQL to do?

If you will permanently all games-World of Warcraft-0 UniformsSwitch all games, World of Warcraft, 0 uniformsThere is no need to execute the Replace function at query time (this may involve changes in the program), and the efficiency will naturally improve.
If you define the final query as a view, the efficiency will be improved (if the source data of a record is not changed, the result of the cache will be returned without the query action)

------to solve the idea----------------------
How can I put all the game-wow-1 in a field?
I suggested adding a few fields, unpacking it, and then draining the MySQL
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.