PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > Getting data in chunks.
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Getting data in chunks.

Réponse
 
LinkBack Outils de la discussion
Vieux 10/04/2008, 03h24   #1
undbund
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Getting data in chunks.

Hi i am trying to retrive data in chunks like 5 at a time or 10 at a
time. Can anyone guide me to tutorials on how to go about doing this.

Thanks
  Réponse avec citation
Vieux 10/04/2008, 06h05   #2
Michael Austin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting data in chunks.

undbund wrote:
> Hi i am trying to retrive data in chunks like 5 at a time or 10 at a
> time. Can anyone guide me to tutorials on how to go about doing this.
>
> Thanks


5 pink pickles? 5 records? 5 columns? 5 words? 5 bytes?
  Réponse avec citation
Vieux 10/04/2008, 06h18   #3
ThanksButNo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting data in chunks.

On Apr 9, 9:05 pm, Michael Austin <maus...@firstdbasource.com> wrote:
> undbund wrote:
> > Hi i am trying to retrive data in chunks like 5 at a time or 10 at a
> > time. Can anyone guide me to tutorials on how to go about doing this.

>
> > Thanks

>
> 5 pink pickles? 5 records? 5 columns? 5 words? 5 bytes?


If it makes any difference, I vote for the pink pickles.

Never seen one, let alone five, so it should be interesting.

;-)
  Réponse avec citation
Vieux 10/04/2008, 06h54   #4
John Andersen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting data in chunks.

On Apr 10, 4:24 am, undbund <undb...@gmail.com> wrote:
> Hi i am trying to retrive data in chunks like 5 at a time or 10 at a
> time. Can anyone guide me to tutorials on how to go about doing this.
>
> Thanks


Lookup the LIMIT feature in the MySQL manual.
John
  Réponse avec citation
Vieux 10/04/2008, 10h55   #5
undbund
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting data in chunks.

On Apr 10, 4:54 pm, John Andersen <j.andersen...@gmail.com> wrote:
> On Apr 10, 4:24 am, undbund <undb...@gmail.com> wrote:
>
> > Hi i am trying to retrive data in chunks like 5 at a time or 10 at a
> > time. Can anyone guide me to tutorials on how to go about doing this.

>
> > Thanks

>
> Lookup the LIMIT feature in the MySQL manual.
> John



I have found out how to do this using LIMIT.

Thanks for all your .

Bye
  Réponse avec citation
Vieux 10/04/2008, 13h50   #6
Gilbert
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting data in chunks.

John Andersen wrote:

> On Apr 10, 4:24 am, undbund <undb...@gmail.com> wrote:
>> Hi i am trying to retrive data in chunks like 5 at a time or 10 at a
>> time. Can anyone guide me to tutorials on how to go about doing this.
>>
>> Thanks

>
> Lookup the LIMIT feature in the MySQL manual.
> John


Does anyone know how LIMIT actually works in practice. I would assume that
the first read would return the first X records starting at record 1. When
the second read happens does the server physically start at X+1 and return
X records or does it actually re-read the first X records to get to the
starting point? And the third read? I guess what I'm getting at is MySQL
smart enough to remember where the last access finished (and if so, how) or
do we end up reading from the start of the table each time?

Does using LIMIT provide an indemnepotant view of the underlying table or
are we vulnerable to changes made in the underlying table between accesses?

Regards
  Réponse avec citation
Vieux 10/04/2008, 14h05   #7
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting data in chunks.

On 10 Apr, 12:50, Gilbert <bugger....@no.spam.com> wrote:
> John Andersen wrote:
> > On Apr 10, 4:24 am, undbund <undb...@gmail.com> wrote:
> >> Hi i am trying to retrive data in chunks like 5 at a time or 10 at a
> >> time. Can anyone guide me to tutorials on how to go about doing this.

>
> >> Thanks

>
> > Lookup the LIMIT feature in the MySQL manual.
> > John

>
> Does anyone know how LIMIT actually works in practice. I would assume that
> the first read would return the first X records starting at record 1. When
> the second read happens does the server physically start at X+1 and return
> X records or does it actually re-read the first X records to get to the
> starting point? And the third read? I guess what I'm getting at is MySQL
> smart enough to remember where the last access finished (and if so, how) or
> do we end up reading from the start of the table each time?
>
> Does using LIMIT provide an indemnepotant view of the underlying table or
> are we vulnerable to changes made in the underlying table between accesses?
>
> Regards


More to the point, suppose you are doing a "LIMIT 0,10".

When you then do a "LIMIT 10,10", what happens if one of the original
first 10 records has now been deleted. Will you then jump over one of
the records that you didn't see in the first hit?
  Réponse avec citation
Vieux 10/04/2008, 14h16   #8
Peter H. Coffin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting data in chunks.

On Wed, 9 Apr 2008 21:18:05 -0700 (PDT), ThanksButNo wrote:
> On Apr 9, 9:05 pm, Michael Austin <maus...@firstdbasource.com> wrote:
>> undbund wrote:
>> > Hi i am trying to retrive data in chunks like 5 at a time or 10 at a
>> > time. Can anyone guide me to tutorials on how to go about doing this.

>>
>> > Thanks

>>
>> 5 pink pickles? 5 records? 5 columns? 5 words? 5 bytes?

>
> If it makes any difference, I vote for the pink pickles.
>
> Never seen one, let alone five, so it should be interesting.


They're usually made from ginger root. Quite tasty.

--
9. If a self-destruct mechanism is necessary, it will not be a large red button
labelled "Danger: Do Not Push". The big red button marked "Do Not Push" will
instead trigger a spray of bullets on anyone stupid enough to disregard it.
--Peter Anspach's list of things to do as an Evil Overlord
  Réponse avec citation
Vieux 10/04/2008, 22h16   #9
Gordon Burditt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting data in chunks.

>> > Lookup the LIMIT feature in the MySQL manual.
>> > John

>>
>> Does anyone know how LIMIT actually works in practice. I would assume that
>> the first read would return the first X records starting at record 1. When
>> the second read happens does the server physically start at X+1 and return
>> X records or does it actually re-read the first X records to get to the
>> starting point? And the third read? I guess what I'm getting at is MySQL


It does need to read the records to the extent of figuring out whether
they are to be selected, or to sort them to determine order.
If the query cache can't be used, it needs to do this on each query.

>> smart enough to remember where the last access finished (and if so, how) or
>> do we end up reading from the start of the table each time?


MySQL is smart enough to NOT make the result of one query depend on
invisible variables set by previous queries. LIMIT is not a cursor.

>> Does using LIMIT provide an indemnepotant view of the underlying table or
>> are we vulnerable to changes made in the underlying table between accesses?


Can you get this by starting a transaction (using InnoDB tables)?

>> Regards

>
>More to the point, suppose you are doing a "LIMIT 0,10".
>
>When you then do a "LIMIT 10,10", what happens if one of the original
>first 10 records has now been deleted. Will you then jump over one of
>the records that you didn't see in the first hit?


LIMIT does not provide you with a cursor. It does not carry over context
from previous queries, except to the extent they modify the database.
If the database changes between your queries, so be it.


  Réponse avec citation
Vieux 11/04/2008, 00h37   #10
Gilbert
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting data in chunks.

Gordon Burditt wrote:

>>> > Lookup the LIMIT feature in the MySQL manual.
>>> > John
>>>
>>> Does anyone know how LIMIT actually works in practice. I would assume
>>> that the first read would return the first X records starting at record
>>> 1. When the second read happens does the server physically start at X+1
>>> and return X records or does it actually re-read the first X records to
>>> get to the starting point? And the third read? I guess what I'm getting
>>> at is MySQL

>
> It does need to read the records to the extent of figuring out whether
> they are to be selected, or to sort them to determine order.
> If the query cache can't be used, it needs to do this on each query.
>
>>> smart enough to remember where the last access finished (and if so, how)
>>> or do we end up reading from the start of the table each time?

>
> MySQL is smart enough to NOT make the result of one query depend on
> invisible variables set by previous queries. LIMIT is not a cursor.
>


Thats what I suspected, which, in conjunction with the fact that the
database could change between requests, makes me wonder what you'd actually
use LIMIT for?

Regards
  Réponse avec citation
Vieux 11/04/2008, 01h09   #11
Michael Austin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting data in chunks.

undbund wrote:
> On Apr 10, 4:54 pm, John Andersen <j.andersen...@gmail.com> wrote:
>> On Apr 10, 4:24 am, undbund <undb...@gmail.com> wrote:
>>
>>> Hi i am trying to retrive data in chunks like 5 at a time or 10 at a
>>> time. Can anyone guide me to tutorials on how to go about doing this.
>>> Thanks

>> Lookup the LIMIT feature in the MySQL manual.
>> John

>
>
> I have found out how to do this using LIMIT.
>
> Thanks for all your .
>
> Bye



unless you are doing an ORDER BY (can be extremely expensive CPU-wise if
you have huge tables) - using LIMIT may not give you the correct results
every time. Records in a relational database are NOT inserted in order.

Look at cursors.

A quick google search produced this example (assuming you are using PHP)


<?php
//connect to the database server
$connection = mysql_connect(
$_SESSION['DB_SERVER']
, $_SESSION['DB_USER']
, $_SESSION['DB_PASSWORD']
);
//get the 'cursor'
$cursor = $mysql_query(
'SELECT * FROM table1'
, $connection
);
//browse through the 'cursor'
while(
$row = mysql_fetch_row(
$cursor
)
){
//process records, one by one.
echo('<div>');
foreach(
$row
as $field
) {
echo('<span>');
echo($field);
echo('</span>');
}
echo('</div>');
}
?>
  Réponse avec citation
Vieux 11/04/2008, 01h09   #12
Michael Austin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting data in chunks.

undbund wrote:
> On Apr 10, 4:54 pm, John Andersen <j.andersen...@gmail.com> wrote:
>> On Apr 10, 4:24 am, undbund <undb...@gmail.com> wrote:
>>
>>> Hi i am trying to retrive data in chunks like 5 at a time or 10 at a
>>> time. Can anyone guide me to tutorials on how to go about doing this.
>>> Thanks

>> Lookup the LIMIT feature in the MySQL manual.
>> John

>
>
> I have found out how to do this using LIMIT.
>
> Thanks for all your .
>
> Bye


Forgot the reference:
http://rpbouman.blogspot.com/2005/09...ith-mysql.html
  Réponse avec citation
Vieux 11/04/2008, 03h33   #13
Gordon Burditt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting data in chunks.

>>>> > Lookup the LIMIT feature in the MySQL manual.
>>>> > John
>>>>
>>>> Does anyone know how LIMIT actually works in practice. I would assume
>>>> that the first read would return the first X records starting at record
>>>> 1. When the second read happens does the server physically start at X+1
>>>> and return X records or does it actually re-read the first X records to
>>>> get to the starting point? And the third read? I guess what I'm getting
>>>> at is MySQL

>>
>> It does need to read the records to the extent of figuring out whether
>> they are to be selected, or to sort them to determine order.
>> If the query cache can't be used, it needs to do this on each query.
>>
>>>> smart enough to remember where the last access finished (and if so, how)
>>>> or do we end up reading from the start of the table each time?

>>
>> MySQL is smart enough to NOT make the result of one query depend on
>> invisible variables set by previous queries. LIMIT is not a cursor.
>>

>
>Thats what I suspected, which, in conjunction with the fact that the
>database could change between requests, makes me wonder what you'd actually
>use LIMIT for?


If you want a Top Ten list (or just Top One) of something, it works fine. Just don't ask for the Second Ten.

You can use LOCK TABLES if you need to, but that blocks updates.
I think transactions will also work for InnoDB tables.

Things may change so slowly you don't care. Does missing one entry
in team rankings really matter when the new game scores are only
entered once a week?

Things may change so quickly you don't care. If the list of the Top 10
Most Volatile Stocks usually changes faster than you can refresh the page,
does it really matter if you get 11-20 or 10-19?

Sometimes up-to-date data matters more than an ordering.

Some databases forbid deletions, or the data just doesn't have many
deletions. How many USA states have been deleted in the last few
decades?

If it is likely that you (the user) want to compare adjacent entries,
don't paginate by full pages. For example, show 1-8, then 6-13,
then 11-18, so there is deliberate overlap between pages.

  Réponse avec citation
Vieux 14/04/2008, 04h00   #14
Michael Austin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting data in chunks.

undbund wrote:
> On Apr 10, 4:05 pm, Michael Austin <maus...@firstdbasource.com> wrote:
>> undbund wrote:
>>> Hi i am trying to retrive data in chunks like 5 at a time or 10 at a
>>> time. Can anyone guide me to tutorials on how to go about doing this.
>>> Thanks

>> 5 pink pickles? 5 records? 5 columns? 5 words? 5 bytes?

>
> Obviously if you are retrieving data from MySQL it would be records!
>
> .
>


Not always the case... if you have a CLOB it is one record, but can be
retrieved in parts - and you could retrieve the CLOB 5 bytes at a time..
being specific in your question will get you a more succinct and
correct answer...
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h01.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,19734 seconds with 22 queries