It is much faster to iterate over an array then a recordset. You should also pass the recordset to a function to return the dictionary. The fewer tasks a subroutine performs the better.
Function RecordsetMap(ByRef rs As ADODB.Recordset, ByVal KeyColumn As Long) As Scripting.Dictionary
Dim Map As New Scripting.Dictionary
Dim Key, Item, Values
Community wiki because the root of the answer (use an MLT to copy the data) was already in the comments. Shoutout to dnoeth and Der Kommissar for already explaining most of this in the comments.
Kendra Little has a great article on this topic. In general, the ALTER TABLE statement can't be assumed to be minimally logged, in particular if it is a size-of-...
join Department on Department.Director = Employee.EmployeeId;
Other than not requiring a subquery, this is generally a better thing to do because you can then easily access the matching Department table if you ever need to select a column from it.
Are you sure that this even works? You aren't joining the employee's ...
The query plan seems to be too complicated because all_constraint is a view and not table. So it's difficult to derive what it's doing.
But from common sense it seems the optimal execution plan would be this:
It first selects all ('P', 'U') records in the inner query
For each of them finds correspondent 'R' records (with loop join)
Filters and sorts what ...
A CTE is an optimization fence. You'll want to try to avoid it and at the least convert it into a subquery.
Do an explicit cast instead of an implicit cast:
0.00 + COUNT(*)
Rather than writing
loan_loan.created_at > '2019-08-15' and
loan_loan.created_at < '2019-09-05'