Need help creating an index

2 views
Skip to first unread message

Jon Wells

unread,
Nov 26, 2009, 10:06:18 PM11/26/09
to InterSystems: MV Community
Hi all,

The goal is to create an index I can us BSCAN (etc.) on from an I-
descriptor. Here's the property I want to use ->

Persistent class -> Playground.jonw.SignUp.cls ->
Property PostingId As O.Posting(MVATTRIBUTE = 15, MVWIDTH = 40);

How do I set up an index on this?

Thanks,
Jon Wells
[We're on 2009.1]


John Lambert

unread,
Nov 26, 2009, 10:37:44 PM11/26/09
to intersy...@googlegroups.com
Jon,

This simplest way is probably to create a scratch file and populate it
with the itype and anything it references. Then do CREATE.INDEX on that
file & item.

Look at the class that is generated for an instant worked example. Copy
the index definition and the method into your class.

Points to watch for:

The index name must be the result of the fixed algorithm based on the
DICT item name. The example will show this. ( This will no longer be a
restriction in 2010.2)

The code in the ITYPE parameter is used for index updates. The code in
the Basic Method is used for object accesses. You can improve this code
by passing the properties it really needs rather than the ID and the
whole item and adjusting the code accordingly. This will also ensure
that the property will be updated if you modify the parameters in the
object that it is computed from.

John Lambert
--
You received this message because you are subscribed to the Google
Groups "InterSystems: MV Community" group.
To post to this group, send email to Cac...@googlegroups.com
To unsubscribe from this group, send email to
CacheMV-u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/CacheMV?hl=en

Jon Wells

unread,
Nov 28, 2009, 2:49:57 PM11/28/09
to intersy...@googlegroups.com, John.L...@intersystems.com
Hi John,

I finally had some time to try this out.

The file/persistent class Playground.jonw.SignUp is a scratch file so I ran -->
CREATE.INDEX Playground.jonw.SignUp PostingId, & BUILD.INDEX Playground.jonw.SignUp PostingId

Which resulted in the following being added to the persistent class ->
Property rawAttr1 As %String(MVATTRIBUTE = 1, MVPROJECTED = 0);

Index indexPostingId On PostingId As Space [ Data = PostingId ];

The attribute, PostingId, has the property -> Property PostingId As O.Posting(MVATTRIBUTE = 15, MVWIDTH = 40);

The dictionary of this file does not appear to be any different after the above.  Also, LIST.INDEX shows nothing (not even an error message when used on a none existent file)
I created a test program ->

[BP, JWW.TEST.INDEX)
* JWW.TEST.INDEX
* 11/28/2009, JONW
*
OPEN 'Playground.jonw.SignUp' TO PJS.FILE ELSE
  CRT "CAN NOT OPEN Playground.jonw.SignUp FILE!"
  STOP
END

SEARCH.ID = ""
NDX.KEY = ""
NDX.ITEM = ""
RESULTS = ""
ANSWER = ""

CRT
CRT
"PLEASE ENTER POSTINGID TO SEARCH FOR: ":
INPUT ANSWER
ANSWER = TRIM(ANSWER)

IF ANSWER = 'Q' OR ANSWER = "q" THEN
  CRT "QUITING BP, JWW.TEST.INDEX PROGRAM..."
  STOP
END

postingid = ANSWER

BSCAN NDX.KEY, NDX.ITEM FROM PJS.FILE, postingid USING 'indexPostingId'

IF NDX.KEY = postingid THEN
  RESULTS = DCOUNT(NDX.ITEM, @AM)
  CRT
  CRT "NDX.KEY = ":NDX.KEY
  CRT "NDX.ITEM = ":NDX.ITEM
  CRT "RESULTS = ":RESULTS
END ELSE
  CRT
  CRT "BSCAN FAILED"
  CRT "NDX.KEY = ":NDX.KEY
  CRT "NDX.ITEM = ":NDX.ITEM
  CRT "postingid = ":postingid
END

STOP

Running this yields ->
ADEV:RUN BP JWW.TEST.INDEX

PLEASE ENTER POSTINGID TO SEARCH FOR: ?814

BSCAN FAILED
NDX.KEY  =
NDX.ITEM =
postingid  = 814
ADEV:

Any suggestions?

Thank you,
Jon Wells

John Lambert

unread,
Nov 28, 2009, 3:00:34 PM11/28/09
to Jon Wells, intersy...@googlegroups.com

Jon,

 

PostingId is not an ITYPE.  Just a simple definition of attr 15.

 

To define an index for a simple attribute:

 

Index indexPostingId On PostingId As Space [ Data = PostingId ];

Is all you need to add and it will make no difference to the generated Dictionary.

You should then be able to run build.index

LIST-INDEX does not currently work L but it is fixed in 2010.1

 

John

Jim Idle

unread,
Nov 28, 2009, 3:04:18 PM11/28/09
to intersy...@googlegroups.com

As an extra tip, I would avoid using BSCAN as though it works perfectly, it is horribly put together (syntactically) and you will find the OPENINDEX related syntax much better, easier, and because of the functionality, more efficient (same indexes underlying it all but because of the way BSCAN works you end up doing more work at the BASIC level when you use BSCAN).

 

Jim

--

Reply all
Reply to author
Forward
0 new messages