DBI Query rows Benchmark

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default DBI Query rows Benchmark

    Hello!

    I have a questionto those lovers of DBI and Databases: which method is faster
    to know the number of rows of a query:

    $sth->rows

    or

    my query but with a COUNT(id) and retrieve the value with:

    $query->bind_columns(undef, \$total);

    The table its 'big' cause it will manage like 12,000 rows.

    In $sth->rows I have this:

    SELECT idport FROM ports WHERE port='$portnumber';

    in the bind_columns case I have

    SELECT COUNT(idport) FROM ports WHERE port='$portnumber'.

    I know that I can test it with EXPLAIN in MySql, however Im testing it with
    150 records, not with 12,000 (or more) that will be the real size of the
    table.

    Thanks!
    --
    Pablo Fischer Sandoval (pablo@pablo.com.mx)
    [url]http://www.pablo.com.mx[/url]
    [url]http://www.debianmexico.org[/url]
    GPG FingerTip: 3D49 4CB8 8951 F2CA 8131 AF7C D1B9 1FB9 6B11 810C
    Firma URL: [url]http://www.pablo.com.mx/firmagpg.txt[/url]
    Pablo Fischer Guest

  2. Similar Questions and Discussions

    1. Deleting specific rows from a returned query result
      I execute a <cfquery> statement block, and that works fine. However, I need to manipulate the return query rows by deleting the ones that do not...
    2. CFFILE output multiple rows from a query
      I have a quiestion about the below. I am working with this method, but I find that my code results in the first record being outputed twice in the...
    3. How to limit # of rows returned from query
      I am looking at setting a limit to the number of rows returned on some of my queries. I was looking at doing something like: <cfoutput...
    4. Query returns no rows...
      Any more input on this? I still can?t get this resolved :(
    5. Select rows where other related rows don't exist
      I would like to select rows from a table where another related row in the same table doesn't exist and the relation key is more than 1 column. ...
  3. #2

    Default Re: DBI Query rows Benchmark

    Thanks!!!
    El día Sunday 07 September 2003 7:59 a Bob Showalter mandó el siguiente
    correo:
    > Pablo Fischer wrote:
    > > Hello!
    > >
    > > I have a questionto those lovers of DBI and Databases: which method
    > > is faster to know the number of rows of a query:
    > >
    > > $sth->rows
    > >
    > > or
    > >
    > > my query but with a COUNT(id) and retrieve the value with:
    > >
    > > $query->bind_columns(undef, \$total);
    > >
    > > The table its 'big' cause it will manage like 12,000 rows.
    > >
    > > In $sth->rows I have this:
    > >
    > > SELECT idport FROM ports WHERE port='$portnumber';
    > >
    > > in the bind_columns case I have
    > >
    > > SELECT COUNT(idport) FROM ports WHERE port='$portnumber'.
    > >
    > > I know that I can test it with EXPLAIN in MySql, however Im testing
    > > it with 150 records, not with 12,000 (or more) that will be the real
    > > size of the table.
    >
    > The latter should be faster, because the server can do all the counting and
    > doesn't have to pass each row back to the client for counting. If there's
    > an index on "port", the count can be determined just by scanning the index,
    > which could be even quicker.
    >
    > In general, you want your queries to return the mininum number of rows
    > necessary. The second query will always return one row, so that's your best
    > bet.
    --
    Pablo Fischer Sandoval (pablo@pablo.com.mx)
    [url]http://www.pablo.com.mx[/url]
    [url]http://www.debianmexico.org[/url]
    GPG FingerTip: 3D49 4CB8 8951 F2CA 8131 AF7C D1B9 1FB9 6B11 810C
    Firma URL: [url]http://www.pablo.com.mx/firmagpg.txt[/url]
    Pablo Fischer Guest

  4. #3

    Default Re: DBI Query rows Benchmark

    Pablo Fischer wrote:
    > Hello!
    >
    > I have a questionto those lovers of DBI and Databases: which method
    > is faster to know the number of rows of a query:
    >
    > $sth->rows
    >
    > or
    >
    > my query but with a COUNT(id) and retrieve the value with:
    >
    > $query->bind_columns(undef, \$total);
    >
    > The table its 'big' cause it will manage like 12,000 rows.
    >
    > In $sth->rows I have this:
    >
    > SELECT idport FROM ports WHERE port='$portnumber';
    >
    > in the bind_columns case I have
    >
    > SELECT COUNT(idport) FROM ports WHERE port='$portnumber'.
    >
    > I know that I can test it with EXPLAIN in MySql, however Im testing
    > it with 150 records, not with 12,000 (or more) that will be the real
    > size of the table.
    The latter should be faster, because the server can do all the counting and
    doesn't have to pass each row back to the client for counting. If there's an
    index on "port", the count can be determined just by scanning the index,
    which could be even quicker.

    In general, you want your queries to return the mininum number of rows
    necessary. The second query will always return one row, so that's your best
    bet.


    Bob Showalter Guest

  5. #4

    Default Re: DBI Query rows Benchmark


    On Sunday, September 7, 2003, at 12:33 PM, Pablo Fischer wrote:
    > Thanks!!!
    > El día Sunday 07 September 2003 7:59 a Bob Showalter mandó el siguiente
    > correo:
    >> Pablo Fischer wrote:
    >>> Hello!
    >>>
    >>> I have a questionto those lovers of DBI and Databases: which method
    >>> is faster to know the number of rows of a query:
    >>>
    >>> $sth->rows
    >>>
    >>> or
    >>>
    >>> my query but with a COUNT(id) and retrieve the value with:
    You should also be aware that the rows method does not always return
    the number of rows from a select (for example in the oracle oci
    libraries it will not always do this, since the size of the return set
    is not necessarily known when control is returned to you from
    execute()).

    George

    George Schlossnagle Guest

  6. #5

    Default Re: DBI Query rows Benchmark

    select max(ID) from tableName;
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139