Skip to content

Remove unnecessary filter looking for temp tables#8716

Closed
jabbera wants to merge 2 commits into
sqlalchemy:mainfrom
jabbera:optimize-mssql-has-table
Closed

Remove unnecessary filter looking for temp tables#8716
jabbera wants to merge 2 commits into
sqlalchemy:mainfrom
jabbera:optimize-mssql-has-table

Conversation

@jabbera
Copy link
Copy Markdown

@jabbera jabbera commented Oct 25, 2022

Description

Remove code from has_table that doesn't do anything. It was originally added as an attempt to fix: #5597. The correct solution was eventually added for: #6910 but the incorrect solution was not removed even though it could be.

This code is not only inefficient but breaks Azure Synapse Analytics dedicated pools as documented here: #8714

This is documented here: https://learn.microsoft.com/en-us/sql/t-sql/functions/object-id-transact-sql?view=sql-server-ver16#remarks

Fixes: #8714

Checklist

This pull request is:

  • A documentation / typographical error fix
    • Good to go, no issue or tests are needed
  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.
  • A new feature implementation
    • please include the issue number, and create an issue if none exists, which must
      include a complete example of how the feature would look.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests.

Have a nice day!

@zzzeek
Copy link
Copy Markdown
Member

zzzeek commented Oct 25, 2022

hi -

what about #7168 ? this seems to remove the code that fixed this issue. Does the test in

def test_has_table_temp_temp_present_both_sessions(self):
still pass?

@zzzeek
Copy link
Copy Markdown
Member

zzzeek commented Oct 25, 2022

hi -

what about #7168 ? this seems to remove the code that fixed this issue. Does the test in

def test_has_table_temp_temp_present_both_sessions(self):

still pass?

OK it seems this was addressed by some other changes and the issue is fine.

OK so this patch if it fixes your problem for azure is likely good for 1.4

@zzzeek zzzeek requested a review from sqla-tester October 25, 2022 21:03
Copy link
Copy Markdown
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision f21772a of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Copy Markdown
Collaborator

New Gerrit review created for change f21772a: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

@jabbera
Copy link
Copy Markdown
Author

jabbera commented Oct 25, 2022

what about #7168 ? this seems to remove the code that fixed this issue.

That change would have never been necessary if the solution here was used in the first place. OBJECT_ID is the correct way to check for the existence of a temp table and it already does session differentiation per my MSFT SQL MVP and the documentation I found online. All of the examples use temp..#blah instead of temp.dbo.#blah, and I don't understand the difference honestly, but it seems to fix my issue and the tempdb space is global.

@CaselIT CaselIT requested a review from sqla-tester October 26, 2022 17:40
Copy link
Copy Markdown
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision e2ac7a5 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Copy Markdown
Collaborator

Patchset e2ac7a5 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

@sqla-tester
Copy link
Copy Markdown
Collaborator

Federico Caselli (CaselIT) wrote:

Interesting. Are pg an mysql broken too?

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

@sqla-tester
Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

it's got to be my test, or maybe the xdist factor. these passed locally

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

@sqla-tester
Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

can't reproduce, no issue. boy I hate temp tables

$ pytest test/dialect/test_suite.py -k HasTable --dburi postgresql://scott:tiger@pg14/test -n2 --dbdriver psycopg --dbdriver pg8000 --dbdriver psycopg
======================================================================== test session starts =========================================================================
platform linux -- Python 3.10.0, pytest-7.1.3, pluggy-0.13.1 -- /home/classic/.venv3/bin/python
cachedir: .pytest_cache
rootdir: /home/classic/dev/sqlalchemy, configfile: pyproject.toml
plugins: typeguard-2.13.3, anyio-3.6.1, forked-1.3.0, xdist-2.4.0, random-0.2
[gw0] linux Python 3.10.0 cwd: /home/classic/dev/sqlalchemy
[gw1] linux Python 3.10.0 cwd: /home/classic/dev/sqlalchemy
[gw0] Python 3.10.0 (default, Nov 5 2021, 17:23:47) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)]
[gw1] Python 3.10.0 (default, Nov 5 2021, 17:23:47) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)]
gw0 [21] / gw1 [21]
scheduling tests via LoadScheduling

test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table_cache
test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table
[gw0] [ 4%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table
test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table_schema
[gw1] [ 9%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table_cache
[gw0] [ 14%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table_schema
test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table_temp_view
test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table_temp_table
[gw0] [ 19%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table_temp_view
[gw1] [ 23%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table_temp_table
test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table_view
[gw0] [ 28%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table_view
test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table_view_schema
[gw0] [ 33%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+pg8000_14_0::test_has_table_view_schema
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table_cache
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table
[gw1] [ 38%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table_cache
[gw0] [ 42%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table_schema
[gw1] [ 47%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table_schema
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table_temp_table
[gw0] [ 52%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table_temp_table
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table_temp_view
[gw1] [ 57%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table_temp_view
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table_view
[gw0] [ 61%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table_view
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table_view_schema
[gw1] [ 66%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg2_14_0::test_has_table_view_schema
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table_cache
[gw0] [ 71%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table_schema
[gw0] [ 76%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table_schema
[gw1] [ 80%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table_cache
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table_temp_view
[gw0] [ 85%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table_temp_view
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table_temp_table
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table_view
[gw1] [ 90%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table_temp_table
[gw0] [ 95%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table_view
test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table_view_schema
[gw1] [100%] PASSED test/dialect/test_suite.py::HasTableTest_postgresql+psycopg_14_0::test_has_table_view_schema

========================================================================= 21 passed in 5.81s ============================================================

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

@sqla-tester
Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

oh. duh. it's the connection pool. these have to stick on the same connection

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

@sqla-tester
Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

@sqla-tester
Copy link
Copy Markdown
Collaborator

Federico Caselli (CaselIT) wrote:

oh indeed

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

@sqla-tester
Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

4 similar comments
@sqla-tester
Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

@sqla-tester
Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

@sqla-tester
Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

@sqla-tester
Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

@sqla-tester
Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

alembic recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158

@sqla-tester
Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

alembic recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4160

@sqla-tester
Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

alembic-recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4160

@sqla-tester
Copy link
Copy Markdown
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4158 has been merged. Congratulations! :)

@sqla-tester
Copy link
Copy Markdown
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4160 has been merged. Congratulations! :)

sqlalchemy-bot pushed a commit that referenced this pull request Oct 29, 2022
Fixed issue with :meth:`.Inspector.has_table` when used against a temporary
table for the SQL Server dialect would fail an invalid object name error on
some Azure variants, due to an unnecessary information schema query that is
not supported on those server versions. Pull request courtesy Mike Barry.

the patch also fills out test support for has_table()
against temp tables, temp views, adding to the has_table() support just
added for views in #8700.

Fixes: #8714
Closes: #8716
Pull-request: #8716
Pull-request-sha: e2ac7a5

Change-Id: Ia73e4e9e977a2d6b7e100abd2f81a8c8777dc9bb
(cherry picked from commit 2af33d79eddc696c0fb1ef749999fa5d0d33f214)
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.

inspector.has_table throws for temp table in Azure Synapse Dedicated Pool MSSQL dialect can't detect temp table.

4 participants