Without practical access, it’s hard to find complex and quick solutions. Some ideas and suggestions:
Without joining in table B, all SQL queries (with index on A.Number) pass until they find the first 50 rows matching your pattern. If the Number values are relatively unique (not many duplicates [this is power]), the lower the Creation_Date value in the index.
Why is the left outer join in B? Is this one value [zero or one], or one - [zero or many]? If the power is small (many duplicates in A), then a connection is required to clearly find the "first 50", otherwise one would think that the connection would not affect performance beyond the need to connect). I can’t see any index on B (in addition, on the column identifier) that matters here. Um, you have an index on B.Id, right? If not, this can slow down a lot (assuming B has a significant number of lines, of course).
For more information, Id wants to look at the connection power and column order and look very carefully at the "with connection" query execution plan.
additions
If A has low power (many duplicates), then the query optimizer may “think” that he will have to use the set B.Id to resolve the order (what needs to be done to find the Top 50). This may explain why he is doing what he is doing.
If they lead to 100% equivalent results, I would recommend replacing the LEFT connection with an INNER connection. In general, query plans can become much simpler when more restrictive join conditions exist.
source share