finding non-unique keys in index. 
Author Message
 finding non-unique keys in index.

Is there a way to find out if an index contains a non-unique key without
reading all the file.    The index was created without the "unique"
parameter.



Tue, 12 Dec 2000 03:00:00 GMT  
 finding non-unique keys in index.

Fran?ois

One way would be to create a new unique index and compare the number of
records that are in the each index.

HTH
--
Steve Quinn
BRUTE Computer Services - Australia

http://www.brutecom.com.au



Quote:
> Is there a way to find out if an index contains a non-unique key without
> reading all the file.    The index was created without the "unique"
> parameter.



Wed, 13 Dec 2000 03:00:00 GMT  
 finding non-unique keys in index.

On Fri, 26 Jun 1998 17:37:50 GMT, "Fran?ois Gagnon"

Quote:

>Is there a way to find out if an index contains a non-unique key without
>reading all the file.    The index was created without the "unique"
>parameter.

Sure there is:

cKey1 := IndexKey()
dbSkip()
if cKey1 == IndexKey()
   ? "Non-Unique key " + cKey1
else
   ? "Unique key " + cKey1
endif

IndexKey is a UDF that returns the value of the current index key.  

HTH
--
Nick Ramsay




Wed, 13 Dec 2000 03:00:00 GMT  
 finding non-unique keys in index.

Quote:

>On Fri, 26 Jun 1998 17:37:50 GMT, "Fran?ois Gagnon"

>>Is there a way to find out if an index contains a non-unique key without
>>reading all the file.    The index was created without the "unique"
>>parameter.

>Sure there is:

>cKey1 := IndexKey()
>dbSkip()
>if cKey1 == IndexKey()

I bet that the above  expresion ALWAYS will evaluate to  .T.    // :-)

Quote:
>   ? "Non-Unique key " + cKey1
>else
>   ? "Unique key " + cKey1
>endif

>IndexKey is a UDF that returns the value of the current index key.

>HTH

Assuming tha the dbf and index are opened...
Local cKey :="", nKeys :=0

// open dbf and index

while !eof()
    ckey := &(IndexKey(0))
    dbskip()
    IF  ckey == &(IndexKey(0))
        ? "Non-Unique key " + ckey
        nKeys++
    ENDIF
end

? Str(nKeys)+" non-unique keys found. So what !?"

Kalimera
Pit V.
Greece

P.S. (IMHO IndexKey() is not a UDF...)



Fri, 15 Dec 2000 03:00:00 GMT  
 finding non-unique keys in index.

Quote:
>Assuming tha the dbf and index are opened...
>Local cKey :="", nKeys :=0

>// open dbf and index

>while !eof()
>    ckey := &(IndexKey(0))
>    dbskip()
>    IF  ckey == &(IndexKey(0))
>        ? "Non-Unique key " + ckey
>        nKeys++
>    ENDIF
>end

>? Str(nKeys)+" non-unique keys found. So what !?"

Your function works ok, but you call &(IndexKey(0)) twice for each record.

LOCAL CurKey,PrevKey
LOCAL nKeys := 0

*- First Record
PrevKey = &(IndexKey(0))
skip

do while !eof()
    CurKey := &(IndexKey(0))
    if CurKey==PrevKey
        ? "Non unique..."
        nKeys++
    endif
    PrevKey := CurKey
    skip
enddo

Un saludo!



Sat, 23 Dec 2000 03:00:00 GMT  
 finding non-unique keys in index.

Quote:
> Your function works ok, but you call &(IndexKey(0)) twice for each record.

> LOCAL CurKey,PrevKey
> LOCAL nKeys := 0

> *- First Record
> PrevKey = &(IndexKey(0))
> skip

> do while !eof()
>     CurKey := &(IndexKey(0))
>     if CurKey==PrevKey
>         ? "Non unique..."
>         nKeys++
>     endif
>     PrevKey := CurKey
>     skip
> enddo

...and both of you missed the obvious speedup of only macro compiling once:

  Local bKeyExpr := &( "{|| " + indexkey( 0 ) + "}" )
  ...
  PrevKey := eval( bKeyExpr )
  ...
     CurKey := eval( bKeyExpr )

--
Take a look in Hagbard's World: |     w3ng - The WWW Norton Guide reader.
http://www.acemake.com/hagbard/ |  ng2html - The NG to HTML converter.
http://www.hagbard.demon.co.uk/ |       eg - Norton Guide reader for Linux.
Free software, including........|   dgscan - DGROUP scanner for Clipper.



Sat, 23 Dec 2000 03:00:00 GMT  
 finding non-unique keys in index.

Quote:
>Jose, your routine tests uniqueness against the first key value, which is
not
> the proper basis.

I think you dont see that the routine updates PrevKey... Look at the basic
body of the routine...

PrevKey := eval(bKeyExpr)
skip

do while ...
    CurKey := eval(bKeyExpr)
    *- Now I have CurKey with the Current Key
    *- And PrevKey with the Previous Key
    ... Compare,...

    *- Now update PrevKey & skip
    PrevKey := CurKey
    skip
enddo

If you work with Clipper 5.3 I suggest to use OrdKeyVal() instead of
&(IndexKey()), and I suposse its as efficient as eval(...) without the
"PreCompilation" &("{||..")

Saludos desde Mallorca.



Mon, 25 Dec 2000 03:00:00 GMT  
 finding non-unique keys in index.

Quote:
>> Your function works ok, but you call &(IndexKey(0)) twice for each

record.

Quote:
>...and both of you missed the obvious speedup of only macro compiling once:

...and all of us were off the point, which was "Is there a way to find out
if an index contains a non-unique key ___without reading all the file___ ".

(But "nobody is perfect!"  -especialy on 42C July)
So, an EXIT statement immediately after the first non-unique key found,
maybe answers, in a way, the question.
I wonder if, a low-level reading-searching of the index file itself, might
help here.

Pit V.
Greece



Tue, 26 Dec 2000 03:00:00 GMT  
 finding non-unique keys in index.

Quote:

> >> Your function works ok, but you call &(IndexKey(0)) twice for each
> >> record.

> >...and both of you missed the obvious speedup of only macro compiling once:

> ...and all of us were off the point, which was "Is there a way to find out
> if an index contains a non-unique key ___without reading all the file___
> ".

Hmm, I don't think anyone was "off the point" as such, all of the examples
showed how to count how many duplicates (well, sort of) were in a database,
finding the first one is a trivial step back using, as you say:

Quote:
> So, an EXIT statement immediately after the first non-unique key found,
> maybe answers, in a way, the question.

Yup, I'd say it answers the question.

Quote:
> I wonder if, a low-level reading-searching of the index file itself, might
> help here.

Depends what you mean by help. The up-side is you might be able to make it a
little bit faster than using just Clipper code, the downside is that you'd
loose any semblance of RDD independence.

--
Take a look in Hagbard's World: |     w3ng - The WWW Norton Guide reader.
http://www.acemake.com/hagbard/ |  ng2html - The NG to HTML converter.
http://www.hagbard.demon.co.uk/ |       eg - Norton Guide reader for Linux.
Free software, including........|   dgscan - DGROUP scanner for Clipper.



Tue, 26 Dec 2000 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Checking for DUPLICATES on non-unique keys

2. Single record, non-unique key

3. how to manage non-unique keys?

4. Finding non-unique rows of a matrix

5. Not so unique Unique Keys

6. Not so unique Unique Keys - :2

7. Newbie: finding the key/index of the min/max element

8. Fixing the FAQ (was Re: Newbie: finding the key/index of the min/max element)

9. HELP ! corrupted index (in index key)

10. finding 1d index in 2d array of indices

11. RealBasic DB: Unique Indexes

12. non-unique auto increment

 

 
Powered by phpBB® Forum Software