Skip to content

Fix #2429: Replaced slow UNION query with optimized all_objects query#2467

Open
LohithaNadimpalli wants to merge 1 commit into
rsim:masterfrom
LohithaNadimpalli:fix-slow-query-2429
Open

Fix #2429: Replaced slow UNION query with optimized all_objects query#2467
LohithaNadimpalli wants to merge 1 commit into
rsim:masterfrom
LohithaNadimpalli:fix-slow-query-2429

Conversation

@LohithaNadimpalli
Copy link
Copy Markdown

Summary:

Replaced the slow UNION-based SQL query in connection.rb with a single query using all_objects to improve performance, as discussed in #2429.

Details:

  • Reduced 4 UNION ALL queries into one optimized query using all_objects.
  • Suggested by Oracle DBAs due to 2-second delay in production.
  • I'm a beginner contributor and wasn’t able to run tests locally.
    Kindly review and let me know if further changes are needed.

Closes #2429

@LohithaNadimpalli
Copy link
Copy Markdown
Author

Hi maintainers! I'm a beginner contributor and excited to make my first PR to this project. Please let me know if anything needs improvement. 🙏

@matthewtusker
Copy link
Copy Markdown

We've done some more research into this and found a DBMS_UTILITY.NAME_RESOLVE function in Oracle which resolves names, and supports db links. It's much faster than the existing SQL, and faster than the all_objects query. I think you should look into that if you're looking to make a contribution to Oracle Enhanced.

@yahonda
Copy link
Copy Markdown
Collaborator

yahonda commented Apr 13, 2026

Thanks for the contribution and the idea to use all_objects. I have opened #2521 which builds on this approach with the following fixes:

  • Alias columns (object_name table_name, object_type name_type) to match the existing result handling code
  • Fix bind parameter count (3 instead of 7)
  • Restore public synonym lookup via OR (owner = 'PUBLIC' AND object_name = :real_name)
  • Resolve synonym targets via a second all_synonyms query (since all_objects does not return the synonym target)
  • Add ORDER BY to preserve the original lookup priority
  • Add a regression test covering table, view, private synonym and public synonym resolution

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slow query, can it be replaced?

4 participants