Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 11 total
Thread Best (most efficient) way to get. Record count?
Wed, May 23 2018 6:50 PMPermanent Link

John AJ Marknette

Avatar

Team Elevate Team Elevate

I don't have access to the source so I can look myself. But am curious as to which is the most efficient way to get if any records exist.?

'SELECT  OID FROM items'

Or

'SELECT Count(OID) as Count FROM items'

OID is a Guid field.

-AJ
Thu, May 24 2018 3:49 AMPermanent Link

Matthew Jones

John AJ Marknette wrote:

> 'SELECT  OID FROM items'

I usually use that with a "TOP 2" or whatever the syntax is. You don't want to process all of the records, so why look at them?

No idea about speed though.

--

Matthew Jones
Thu, May 24 2018 4:21 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

John

My bet would be SELECT COUNT(*) FROM table


However, just to build a little on what Matthew says -

SELECT field FROM table

will build a result set. If its sensitive then you're ok but if not then files have to be written so will be slower. It will also (surprisingly enough) be faster on an indexed column.



Roy Lambert
Thu, May 24 2018 11:04 AMPermanent Link

John AJ Marknette

Avatar

Team Elevate Team Elevate

"Matthew Jones" wrote:

I usually use that with a "TOP 2" or whatever the syntax is. You don't want to process all of the records, so why look at them?

TOP n is what I would have used with SQL Server, but Elevate doesn't support it.

-AJ
Thu, May 24 2018 12:41 PMPermanent Link

Raul

Team Elevate Team Elevate

On 5/24/2018 11:04 AM, John AJ Marknette wrote:
> TOP n is what I would have used with SQL Server, but Elevate doesn't support it.

Would RANGE work ?

Raul
Thu, May 24 2018 1:12 PMPermanent Link

John AJ Marknette

Avatar

Team Elevate Team Elevate

>Raul wrote:

>Would RANGE work ?

Actually yes it would in my case, as all I'm really doing is checking if the table is empty or not. Thanks.

-AJ
Fri, May 25 2018 7:55 AMPermanent Link

Matthew Jones

FWIW, I could not believe that it didn't have TOP, so checked my SQLBuilder class which I know uses it:

{$IFDEF USE_ELEVATE_DB}
   if m_nTopCount > 0 then
       szSQL := szSQL + ' RANGE 1 TO ' + IntToStr(m_nTopCount);
{$ELSE}
   if m_nTopCount > 0 then
       szSQL := szSQL + ' TOP ' + IntToStr(m_nTopCount);
{$ENDIF}

So it is effectively the same thing.

--

Matthew Jones
Fri, May 25 2018 11:52 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

AJ,

The fastest way is to make sure that you set the RequestSensitive property to True, and then just issue:

SELECT * FROM MyTable

and check the record count.

The second fastest way would be:

SELECT COUNT(*) FROM MyTable

And by "second fastest", I mean you probably won't be able to tell the difference between the two. Smile

Tim Young
Elevate Software
www.elevatesoft.com
Fri, May 25 2018 12:52 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Tim


>And by "second fastest", I mean you probably won't be able to tell the difference between the two. Smile

I can't let that go by unchallenged - how do you know its the second fastest if you can't tell the difference Smiley

Roy
Fri, May 25 2018 1:58 PMPermanent Link

Raul

Team Elevate Team Elevate

On 5/25/2018 12:52 PM, Roy Lambert wrote:
> I can't let that go by unchallenged - how do you know its the second fastest if you can't tell the difference Smiley

Kind of curious now as well.

Totally guessing here but

Would "select * ..." not have to load at least 1st record (for current
cursor) and if one has blob/memo in that list would that not result in
another table lookup

I guess count(*) might do same but it could be optimized to not to and
just load from table header the record count

I don't have big enough tables handy - i'm getting 0 sec for both for
data i have handy at this time.

Raul
Page 1 of 2Next Page »
Jump to Page:  1 2
Image