MSSQL multi-table reflection of temp tables still queries tempdb catalog by name; can deadlock

Đang mở
#13,789 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, sql
Lĩnh vực
databases

Hướng nghiên cứu

Start with the SQL Server dialect's get_multi_* reflection methods, especially get_multi_pk_constraint(), and the tempdb pass that filters tempdb.sys.* catalog views by resolved name. Compare it with the 2.0 column query, which already filters on object_id(). Done means the tempdb queries for PK, columns, indexes and table comment filter on the resolved object id, with a test showing reflection no longer blocks while another session holds temp table locks.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug reflection SQL Server

#13754 changed the resolution of a #temp name to its internal tempdb name to
use object_id(), so that the lookup only sees the current session's table.
However, the SQL Server get_multi_* methods added in 2.1 (#8430) then run
their bulk catalog queries against tempdb.sys.*, filtering on the resolved
name rather than on the object id:

SELECT ...
FROM tempdb.sys.key_constraints
JOIN tempdb.sys.objects ON key_constraints.parent_object_id = objects.object_id
JOIN tempdb.sys.schemas ON ...
JOIN tempdb.sys.index_columns ON ...
JOIN tempdb.sys.columns ON ...
JOIN tempdb.sys.indexes ON ...
WHERE key_constraints.type = 'PK'
  AND schemas.name = 'dbo'
  AND objects.name IN ('#mr_leak_tmp_____...0000000012CF')

Nothing in these queries limits them to one object, so the server is free to
read catalog rows for other sessions' temp tables in tempdb. When another
session is creating temp tables inside an open transaction, those rows are
locked, so reflection blocks or deadlocks:

(pyodbc.Error) ('40001', '[40001] [Microsoft][ODBC Driver 18 for SQL Server]
[SQL Server]Transaction (Process ID 73) was deadlocked on lock resources with
another process and has been chosen as the deadlock victim. Rerun the
transaction. (1205) (SQLFetch)')

This came up in CI in get_multi_pk_constraint(). The columns, indexes and
table comment queries in the tempdb pass use the same name-based filter.

The tempdb pass should filter on the object id that was already resolved.

2.0 is not affected. There, temp table reflection only queries tempdb for
columns, and that query already filters on object_id().

Ngôn ngữ chính
Python
Star
12.3k
Fork
1.8k
Merge trung bình
2 ngày 10 giờ
Pull request đã merge (30 ngày)
9

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của sqlalchemy/sqlalchemy

Tất cả issue của sqlalchemy/sqlalchemy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.