Skip to content

Conversation

@klskvmr
Copy link

@klskvmr klskvmr commented Apr 11, 2025

AND condition problem
The tag filter did not work for objects with multiple tags in the following cases:

  • With search conditions for multiple tags via AND
  • With the != operator

Reason:
Previously, inside the *_with_tags views (used for searching by tags), a left join was made with the tags_* views (containing the tags), and for each tag of one entity there was a separate row in the table.
Tags for one entity were in different rows and the condition with IN did not work, since it works by rows.

Example:
WHERE ( vms_with_tags.tag_name IN ('tag-1') AND vms_with_tags.tag_name IN ('tag-2') )
this condition will always be false for objects with multiple tags.

What was done to solve the problem
The tags columns types in *_with_tags views have been changed from text to arrays for support and improve tags searching with multiple conditions without increasing the complexity of the resulting SQL query.

To support filtering by tags, it was decided to use arrays. Now, to search for one or more tags, the array intersection operation (&&) is used, which allows for the correct use of several consecutive conditions with tags

The edits affected tag filters on the pages:

  1. Compute -> Virtual Machines
  2. Compute -> Hosts
  3. Administration -> Users

Cases
All functionality is preserved, only a filter by several tags via AND is additionally supported.

  Filter search cases Result or resulting selection
1 Filter by tag with the = operator WORKS
Objects with the searched tag and objects with its nested tags.
Nested tags are taken into account!
i.e. tags nested in the searched tag will also be included in the resulting selection
2 Filter by tag with the != operator DIDN'T WORK ON OBJECTS WITH MULTIPLE TAGS (FIXED)
Objects not marked with the tag from the condition.
Nested tags are not taken into account!
3 Filter by tag with operators
<, >, <=, >=
NOT SUPPORTED
4 Filter by several tags via OR WORKS
Objects with the searched tags and objects with tags nested in them.
Nested tags are taken into account!
5 Filter by two tags via AND DIDN'T WORK ON OBJECTS WITH MULTIPLE TAGS (FIXED)
Objects containing all the searched tags or tags nested in them.
Nested tags are taken into account!
6 Filter with tag and with another field WORKS
7 Free text search WORKS
8 Search by regular expression
e.g. tag = test_ta*
WORKS
9 Search by regular expression for =
e.g. tag = test_ta*
WORKS
10 Search by regular expression for !=
e.g. tag != test_ta*
DIDN'T WORK ON OBJECTS WITH MULTIPLE TAGS (FIXED)
Objects not marked with the tag from the condition.
Nested tags are not taken into account!

Changes introduced with this PR

Are you the owner of the code you are sending in, or do you have permission of the owner?

y

@klskvmr klskvmr marked this pull request as draft April 12, 2025 06:06
@klskvmr klskvmr force-pushed the support-search-with-multiple-tags-conditions branch from fda1798 to 8b031a9 Compare April 14, 2025 08:31
The tags columns types in *_with_tags views have been changed from text to
arrays for support and improve tags searching with multiple conditions without increasing the complexity of the resulting SQL query.

Signed-off-by: Mari Istomina <[email protected]>
@klskvmr klskvmr force-pushed the support-search-with-multiple-tags-conditions branch from 8b031a9 to db6d06a Compare April 14, 2025 08:37
@klskvmr klskvmr changed the title engine: Support search with multiple tags conditions engine: Support for expressions with 'AND' and 'not equal' for objects with multiple tags Apr 14, 2025
@klskvmr klskvmr changed the title engine: Support for expressions with 'AND' and 'not equal' for objects with multiple tags engine: Support for 'AND' and 'not equal' expressions for objects with multiple tags Apr 14, 2025
@klskvmr klskvmr marked this pull request as ready for review April 14, 2025 14:42
@klskvmr
Copy link
Author

klskvmr commented Apr 14, 2025

BEFORE FIX

Filters by tags with... (for objects with multiple tags)

  • Search conditions for multiple tags via AND

ovirt_before_fix_ and_condition

  • The != operator

ovirt_before_fix_not_equals_1

@klskvmr
Copy link
Author

klskvmr commented Apr 14, 2025

AFTER FIX

Filters by tags with... (for objects with multiple tags)

  • Search conditions for multiple tags via AND

ovirt_after_fix_end

  • The != operator

ovirt_after_fix_not_equals

Copy link
Contributor

@JasperB-TeamBlue JasperB-TeamBlue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, only thing that bothers me is that the tag string used as a parameter in the expressions is capital sensitive while this is not the case for expressions regarding the name of a vm. Due to this not being a previous functionality on the main branch it does not concern the scope of this patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants