Subject: Re: Select count(*) in Oracle and MySQL From: Mladen Gogala Date: 21 Sep 2007 14:18:45 GMT Message-ID: <46f3d2c5$0$1342$834e42db@reader.greatnowhere.com> References: <1190227221.320339.178380@50g2000hsm.googlegroups.com> <1190231664.266902.149390@50g2000hsm.googlegroups.com> Bytes: 2619 Lines: 32 NNTP-Posting-Host: bdcb1be6.reader.greatnowhere.com Path: text.usenetserver.com!out01b.usenetserver.com!news.usenetserver.com!in01.usenetserver.com!news.usenetserver.com!out.nntp.be!prop4-west.newsfeeds.com!news-in2.spamkiller.net!news1.greatnowhere.com!news1.greatnowhere.com!195.13.230.46.MISMATCH!reader.greatnowhere.com!not-for-mail Newsgroups: comp.databases.oracle.server X-Trace: DXC=4oQ;Nnj9lNF3Z=@AUi>jeE]XKbj2VKD@Jn1RJ3gdIg\K];>oiM_Wl^F2h=o9Y@GCb@55:h3U91eTHU]V1IaTm@^D@o4f4SGCa7e3>I8nLdBQba_0XKK1S@cUHefITeYOEFo^6E5kX=GN User-Agent: Pan/0.132 (Waxed in Black) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NNTP-Posting-Date: 21 Sep 2007 14:18:45 GMT X-Complaints-To: usenet@greatnowhere.com Xref: usenetserver.com comp.databases.oracle.server:435377 X-Received-Date: Fri, 21 Sep 2007 10:20:51 EDT (text.usenetserver.com) On Wed, 19 Sep 2007 12:54:24 -0700, Occidental wrote: > I need the count(*) because I want to know how many rows there are in > the table. > I am not, as the other contributor to the thread implied, trying to > compare Oracle to MySQL, I am simply interested in determining whether > the long runtime of the Oracle query is normal or reflects some error in > the installation. If MySQL can do it, why not the Oracle? It seems > rather absurd that a Database Management System does not know at any > given time how many rows there are in the tables it "manages". There is nothing preventing you from creating a trigger firing after insert or delete, for each row, maintaining the number of rows in a separate table. Oracle doesn't need that number so it doesn't maintain it. It does, however, give you all the necessary facilities to maintain that number yorself. In case you decide to do that, you should be aware that such a trigger is an equivalent of an exclusive lock on the table for the duration of a transaction. Only one transaction, the one holding the lock on the count, will be able to insert at any given count. Also, you will have a ton of expensive transaction restarts when transactions discover that the value they have been waiting for has changed since the transaction has started. In other words, you will turn OLTP into LIETP, transaction processing with speeds like the ones on Long Island Expressway. In case you don't really know what LIE looks like, it suffices to say that it is called "world's largest parking lot". -- http://www.mladen-gogala.com