Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Speeding up a lookup with a large character field
Message
From
12/02/2002 03:55:00
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00618638
Message ID:
00618714
Views:
12
>I have a cursor that contains every directory on my hard drive. Given a path, I need to find the record. Even taking a chance by limiting the field to 240 characters so I can SEEK instead of LOCATE, it's still unacceptably slow.
>
>I'm wondering if it's possible to make it faster. I thought about making a smaller key field that takes the full path and condenses it into something smaller. There are a couple problems with that, though. First, I don't have any idea how to change the path into something smaller that will still be unique. Second, whatever function does the conversion, plus the SEEK after needs to be faster than just SEEKing on the path.
>
>Anyone have any suggestions?
>
>Thanks,
>
>Michelle


Michelle,

Haven't tested it but this should work.

First, create a small index. Nothing is guaranteed to be unique, but the distribution should be ok
select TheTable
local sCollate
sCollate = set('Collate')
set Collate to 'Machine'
index on bintoc(val(sys(2007, ThePath))) tag ThePath
set Collate to (sCollate)
Next, create a function to help you finding out whether something is in

? IsItIn('C:\tmp\ppp\aaa\ccc\ppp.txt', 'TheTable')
Will return TRUE if in and be postioned on the record
*--------------------------------------------------------------------------
function IsItIn(PathToFind, TheTable)

	local IndexedKey, s, OldOrder, sCollate, FoundIt
	
	s = select(0)
	select (TheTable)
	OldOrder = order()
	sCollate = set('Collate')
	set Collate to 'Machine'
	
	IndexedKey = bintoc(val(sys(2007, PathToFind)))
	set Order to ThePath
	=seek(IndexedKey)
	
	FoundIt = FALSE
	
	scan rest for ( bintoc(val(sys(2007, ThePath))) == IndexedKey )
		if( ThePath == PathToFind )
			FoundIt = TRUE
			exit
		endif
	endscan
	
	set order to &OldOrder
	select (s)
	set Collate to (sCollate)
	
	return FoundIt  && and still on the record

endfunc
*--------------------------------------------------------------------------
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform