|
Posted by xhoster on June 9, 2008, 12:34 pm
Please log in for more thread options > avilella@gmail.com wrote:
> > Hi,
> >
> > I would like to know how I could move the select count I am doing in
> > mysql on the perl side:
> >
> > mysql -hhost -uanonymous mydb -e "select count(status), status from
> > table group by status order by null"
> >
> > to instead something like:
> >
> > mysql -hhost -uanonymous mydb -e "select status from table order by
> > null" | perl "give me the count numbers"
If the number of distinct "status" is small, then
... | perl -lne '$h++; END {print "$_\t$h" foreach keys %h}'
There is a possibility that when used in this way, mysql will read the
entire table into memory before starting to write it out to the pipe. If
so, there is a way to tell it not to. I don't recall which is the default.
You might want to look into that.
If you use DBI, which may be a good idea, then I know the default is to
read the results into memory up front, which would probably be a bad idea
(because if the results were small enough to fit in memory, you'd probably
just stick with using the mysql group by in the first place.
> If the table is large that's a major "lose"
Or not. AFAICT, mysql's "group by" always uses a sort, even when a hash
would be much more efficient. Perl uses whatever you tell it to.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
|