CMDB GlideRecord querying
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 08:28 AM
Hello.
Our CMDB has a class extended from cmdb_ci that has a bunch of subclasses extended from it. The current ask is to find a way to search a subset of these subclasses for specific criteria. For example, if this class has subclasses A-H and we want to search A, C, D, E, and G, how do we best do that?
We have 3 options here:
1) Individually search each of the 5 subclasses we are looking for. Only problem is that this solution is not extendable and would require significant rework if we add more subclasses to this search. The other problem is that Class G is actually ALSO refers to class A as a parent, meaning that we would likely have to search for G based on each instance of class A.
2) Search the entire class and simply ignore CIs that are part of the classes we don't want (B, F, and H).
3) Use the IN operator a sys_class_name query for A, C, D, E, and G.
Which is the more efficient way to do this?
(postscript: Yes, I am aware that there are better ways to query this class, maybe by adding an indexed categorization to separate these classes or moving these subclasses down a level and adding two more classes between the main class and the classes A-H so that we can sort the classes A-H into these new subclasses. However, the design of the structure of our CMDB is now frozen and I can no longer change it).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 01:47 AM
Options 2 and 3 seem equivalent. Option 2 uses negative conditions to exclude the records that you do not want while option 3 uses positive conditions to only include the records that you do want. I would expect the performance to be the same in most situations.
Option 1 will be slower except in rare cases. It is almost always faster to do one query than to do multiple queries. If B contains 1,000,000 records and A,C,D,E and G are each less than 1000 records, then 1 will probably be faster. On the other hand, there is a chance that option 3 might allow the system to utilize an index (which it has) on sys_class_name and that option 3 could win this race. Option 2 would lose here since indices are never used for negative tests.
I would vote for option 3.