473,408 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

performance questions

Hi!
My company make several flash-based games, and I use php to communicate
with
mysql to provide highscore-lists.

My problem is this:
When I save a player's score in the mysql-table, I want to find which
place
the player got with his score (today). To get this I have tried two
different solutions, which both works, but are very ineffective: (The
Time-field is a DateTime type, and I have Score and Time as Indexes.
The Score-field is a DECIMAL (20,2))

1) SELECT COUNT(*) FROM table WHERE Score>=$score AND Time>CURDATE().
- or -
2) SELECT Score FROM table WHERE Score>=$score AND Time>CURDATE().

.... $place = mysql_num_rows($result)

Both give the right result, but the problem is that when there are many

players playing at the same time, and the table consists of several
million
records, the query is just too heavy for the mysql-server, and it
breakes
down.

So my question is: Are there any better ways of getting a player's
place?

Ole Johan, Norway

Aug 4 '06 #1
1 1939
"ojorus" <oj****@hotmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Hi!
My company make several flash-based games, and I use php to communicate
with
mysql to provide highscore-lists.

My problem is this:
When I save a player's score in the mysql-table, I want to find which
place
the player got with his score (today). To get this I have tried two
different solutions, which both works, but are very ineffective: (The
Time-field is a DateTime type, and I have Score and Time as Indexes.
The Score-field is a DECIMAL (20,2))

1) SELECT COUNT(*) FROM table WHERE Score>=$score AND Time>CURDATE().
- or -
2) SELECT Score FROM table WHERE Score>=$score AND Time>CURDATE().

... $place = mysql_num_rows($result)

Both give the right result, but the problem is that when there are many

players playing at the same time, and the table consists of several
million
records, the query is just too heavy for the mysql-server, and it
breakes
down.

So my question is: Are there any better ways of getting a player's
place?

Ole Johan, Norway
Unfortunately, both those solutions must search the entire db looking for
'Score >= $score'... you probably need to divide your db into smaller tables
of score ranges so that the queries don't take as long:

table names:

Scores_0thru100
Scores_101thru200
....

well, you get the idea. Then just place some PHP logic to
INSERT/UPDATE/SELECT the $score into/from the proper table.

Norm
Aug 6 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Brian Patterson | last post by:
I have noticed in the book of words that hasattr works by calling getattr and raising an exception if no such attribute exists. If I need the value in any case, am I better off using getattr...
0
by: Jack Coxen | last post by:
------_=_NextPart_001_01C3584E.5FF65B60 Content-Type: text/plain; charset="iso-8859-1" I've gone through the mailing list archives, read the appropriate parts of the manual and searched the...
1
by: Tim Smith | last post by:
Hi, I have a table ORDER_DETAIL with 22 million rows which has an index of (person_id, code_id, created_dtt) I have another ORDER table with 5 million rows which has an index of (order_dtt,...
2
by: Unruled Boy | last post by:
1.The follow two ways to declare one object: any difference? especially its performance. a.Private m_objMyObject As MyObject=New MyObject() b.Private m_objMyObject As MyObject m_objMyObject=New...
115
by: Mark Shelor | last post by:
I've encountered a troublesome inconsistency in the C-language Perl extension I've written for CPAN (Digest::SHA). The problem involves the use of a static array within a performance-critical...
13
by: bjarne | last post by:
Willy Denoyette wrote; > ... it > was not the intention of StrousTrup to the achieve the level of efficiency > of C when he invented C++, ... Ahmmm. It was my aim to match the performance...
2
by: 1944USA | last post by:
I am re-architecting a C# application written as a multithreaded Windows Service and trying to squeeze every bit of performance out of it. 1) Does the thread that an object is instantiated on...
11
by: ZenRhapsody | last post by:
Has anyone done any performance testing between new generic Lists and single dimensional arrays? I really like the code flexibility the List provides since I don't know how many items I will...
8
by: Gary Wessle | last post by:
Hi while I am reading this C++ book, I noticed the iterator is being used to loop through a container, say a vector. I am used to use "for(int=0;i<vec.size();++i)" which is better to use? ...
1
by: jehugaleahsa | last post by:
Hello: I am experiencing performance related issues when my custom data structures work with value types. I use generics to prevent boxing wherever I can. For instance, I use IEqualityComparer,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.