Get objects performance optimization#297
Merged
eric-eclecticiq merged 7 commits intomasterfrom Dec 15, 2025
Merged
Conversation
saaj
approved these changes
Dec 15, 2025
| ), | ||
| ) | ||
| version_filters.append( | ||
| max_versions_subq == taxii2models.STIXObject.version |
Contributor
There was a problem hiding this comment.
I'd prefer a JOIN to a correlated subquery. Some databases are good at rewriting such queries automatically, but I wouldn't bet on all the supported ones doing it well. And JOINs also easier to read (at SQL level). But not sure how good it lends itself to given version filtering code. So up to you.
Contributor
Author
There was a problem hiding this comment.
I assume you mean JOIN. The problem I saw is that TAXII2 is allowing to return both the first and last elements at the same time or any specific version. But in the first case, that would add 2 disjoint joins that would return no result.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Getting objects from a collection with
enterprise-attackdata was very slow. It took more than 12s on my computer while there are only ~20k objects. Also, adding alimit=1did not improve the performance.Optimizations
Query to find last/first
Note:
lastis the default is no option is provided on the API.Initially the query was:
with plan:
I updated the query to only look for the versions of the current row, not all:
with new plan:
The query is also much more simpler.
The index is not compatible with collection id filter
Change
ix_opentaxii_stixobject_date_added_idtoix_opentaxii_stixobject_col_date_added_idby adding thecollection_idas first parameter.New plan:
Do not count more than necessary
The API puts in the response, a
moreboolean to inform if the pagination could return more results. Initially, it was counting all elements independently of the limit. Now, it is counting at most limit + 1 objects.Results