473,486 Members | 2,429 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

MySQL/PHP Question

Hi,

Just a quick question about performance with MySQL & PHP. If I had a table
in a MySQL database with about 100,000 records in it and I need to find the
last record is there a quick way to do this, other than going through the
whole database to find the last record? Would the amount of records in the
table cause major performance problems?

For example, if I had a html form that people used to log something and
needed to display a unique number each time the page was loaded, reason
being thas this unique number could be given to people as a reference
number.

The reason I'm asking is because I've used an Access database (an ODBC
connection) before and with a large amount of records in the table it can
take up to about 12 seconds for a page to load. Would using MySQL
dramatically speed this up anyway?

Thanks,

Tony.
Jul 17 '05 #1
8 4473
A MySql table can hold up to 2GB of data. It's been my experience that
you will start to see performance issues around 1GB.

Jul 17 '05 #2
Tony Clarke wrote:
Hi,

Just a quick question about performance with MySQL & PHP. If I had a table
in a MySQL database with about 100,000 records in it and I need to find the
last record is there a quick way to do this, other than going through the
whole database to find the last record? Would the amount of records in the
table cause major performance problems?
100,000 records is nothing. Not even to Accesss, I'd think.

In a properly indexed table, picking the first or last record should
happen in an instant, regardless of how many records there are.
For example, if I had a html form that people used to log something and
needed to display a unique number each time the page was loaded, reason
being thas this unique number could be given to people as a reference
number.
If you give each logged item a unique number (this makes for a good
primary key in your table, btw), retrieving that record should be very
fast as long as there's an index that column.
The reason I'm asking is because I've used an Access database (an ODBC
connection) before and with a large amount of records in the table it can
take up to about 12 seconds for a page to load.
A full scan (if there's no index) across 100k records should happen
significantly faster than 12 seconds, even with Access..?

Based on your very first question, I'm guessing you actually retrieve
all 100k rows of data and iterate through it until you find the one
record you're looking for?

If this is the case, a simple modification to your SQL query should work
wonders.
Depending on what you're trying to accomplish, either add a WHERE
statement, to only select the row with a matching value, or if you're
looking for the first/last row, add ORDER BY and LIMIT or TOP to select
only the first row.

If you already do it like this, make sure you have an index on the
column in question. I never did stuff an Access table with 100k+ rows,
but I'm sure _any_ relational DB can handle that just fine.
Would using MySQL
dramatically speed this up anyway?


Why MySQL, btw? I went from Access databases to MySQL as well, but only
because I didn't know any better.

These days, I'm reluctant to touch MySQL with my nine-foot pole.
There are other free databases out there which do the job a whole lot
better. I suggest you use PostgreSQL or Firebird if you have access to
one of those, or maybe SQLite if you're on PHP5 and don't have to worry
about extreme load.
Jul 17 '05 #3
If you know the number of rows in the table then you could use the
following query:

SELECT * FROM <table> LIMIT <offset>,<row_count>

Replacing table, offset and row_count with the appropriate values.
Regards

Richard

Jul 17 '05 #4
On Thu, 9 Dec 2004 12:35:25 -0000, "Tony Clarke"
<cl*****@eircom.net> posted:
Hi, Just a quick question about performance with MySQL & PHP. If I had a table
in a MySQL database with about 100,000 records in it and I need to find the
last record is there a quick way to do this, other than going through the
whole database to find the last record? Would the amount of records in the
table cause major performance problems?


I asked the same question on another forum a couple weeks ago and
learned:
$result = mysql_query("SELECT COUNT(*) FROM table");
$number_of_last = mysql_result($result, 0, 0) + 1;
Mike

Jul 17 '05 #5
.oO(MikeSoja)
I asked the same question on another forum a couple weeks ago and
learned:

$result = mysql_query("SELECT COUNT(*) FROM table");
$number_of_last = mysql_result($result, 0, 0) + 1;


Useless. With the above code you only know the number of records in the
database, but this doesn't necessarily have to be the number of the last
record (if it has a number at all).

What would you do next with the variable $number_of_last?

Micha
Jul 17 '05 #6
.oO(Tony Clarke)
Just a quick question about performance with MySQL & PHP. If I had a table
in a MySQL database with about 100,000 records in it and I need to find the
last record is there a quick way to do this, other than going through the
whole database to find the last record? Would the amount of records in the
table cause major performance problems?
100.000 records are peanuts. Question is what makes a "last record"?
Do they have some kind of numeric ID, which can be used to order them?
The reason I'm asking is because I've used an Access database (an ODBC
connection) before and with a large amount of records in the table it can
take up to about 12 seconds for a page to load.


There was definitely something wrong, either with the database/query or
with the script.

Micha
Jul 17 '05 #7
On Thu, 09 Dec 2004 19:20:00 +0100, Michael Fesser <ne*****@gmx.net>
posted:
.oO(MikeSoja)
I asked the same question on another forum a couple weeks ago and
learned: $result = mysql_query("SELECT COUNT(*) FROM table");
$number_of_last = mysql_result($result, 0, 0) + 1;

Useless. With the above code you only know the number of records in the
database, but this doesn't necessarily have to be the number of the last
record (if it has a number at all).
Well, it would be up to the guy who asked the question exactly what
constituted a "last" record, but I believe the query above can be
ORDERED as wished.
What would you do next with the variable $number_of_last?


On my own little set of web pages I report it as a Visitor Counter.

Mike

Jul 17 '05 #8

"Michael Fesser" <ne*****@gmx.net> wrote in message
news:r5********************************@4ax.com...
.oO(Tony Clarke)
Just a quick question about performance with MySQL & PHP. If I had a tablein a MySQL database with about 100,000 records in it and I need to find thelast record is there a quick way to do this, other than going through the
whole database to find the last record? Would the amount of records in thetable cause major performance problems?


100.000 records are peanuts. Question is what makes a "last record"?
Do they have some kind of numeric ID, which can be used to order them?
The reason I'm asking is because I've used an Access database (an ODBC
connection) before and with a large amount of records in the table it can
take up to about 12 seconds for a page to load.


There was definitely something wrong, either with the database/query or
with the script.

Micha


Firstly, thank you to everyone who answered, I have learned a lot.

Yes there is a numeric ID that I use as reference number. Yes, the reason it
was taking about 12 seconds was because I was forming the query badly (as
Frank said I was retrieving all data instead of what I was looking for).

Thanks again,

Tony.
Jul 17 '05 #9

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

Similar topics

19
8673
by: Westcoast Sheri | last post by:
To keep track of how many fruits my visitors buy, I use a mySQL database (2 columns: "fruit" and "quantity")....so can we make these following mySQL queries work somehow? (visitor buys 5...
0
2295
by: MJL | last post by:
This is a mysql/php question (but a little more on the mysql side.) The two are so closely related these days, I thought it would be ok to ask here. I installed on my Suse Linux system mysql 4.0...
2
4492
by: pieter_hordijk | last post by:
Hi all, maybe this isn't a php question, but a MySQL question. If so I'm sorry for asking you guys to help me :) I know this question is asked often in NGs, but I couldn't find the answer...
2
1549
by: kimshapiro100 | last post by:
Question on PhP, MySQL I am thinking of a consumer internet business for which I will have to have a database driven site built. I am thinking of using PhP, MySQL as the main technologies...
39
8366
by: Mairhtin O'Feannag | last post by:
Hello, I have a client (customer) who asked the question : "Why would I buy and use UDB, when MySql is free?" I had to say I was stunned. I have no experience with MySql, so I was left sort...
1
2294
by: Jim Carlock | last post by:
I have a couple questions about MySQL involving which version of MySQL to use. I'm looking for minimal memory use on a Windows XP machine. Which version would be best for this? And can anyone...
15
4562
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
5
4541
by: news.telia.net | last post by:
Hi! I have a question. I have installed php and mysql on an apache-server on windows and I can't connect to the server. I tried to create a database (since I am trying to learn howto). My...
27
3868
by: gerrymcc | last post by:
Hello, I'm a php/mysql beginner... Is there any way of making the mysql command line client full-screen? Sometimes it's easier to use the client than go thru php, but since it's only about 80...
0
6967
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
7132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6846
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
7341
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
5439
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
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
600
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.