microsoft / microsoft/mssql-python

True async query execution

Đang mở
#9 19 bình luận 24 reaction 1 người được giao Xem trên GitHub

@sumitmsft đang làm issue này rồi.

Từ ngày 3/3/2025.

area: api-compliance enhancement triage done
Ngôn ngữ chính
Python
Star
473
Fork
60
Merge trung bình
2 ngày 11 giờ
Pull request đã merge (30 ngày)
36

Mô tả

Is your feature request related to a problem? Please describe.

Currently, mssql-python does not support true async execution, forcing developers to use thread-based workarounds (asyncio.to_thread() or aioodbc). This leads to performance limitations, increased memory usage, and suboptimal scalability in high-throughput applications, such as web servers and data processing pipelines.

For applications using FastAPI, Django Async, or AI/ML workloads, true async support is critical for handling multiple concurrent database operations efficiently. Without it, developers face blocking I/O that slows down event-driven applications.

Describe the solution you'd like
  • Truly non-blocking I/O using asyncio (asyncio.StreamReader / asyncio.StreamWriter).
  • Async query execution with await conn.execute("SELECT ...").
  • Streaming large result sets asynchronously using async for row in cursor.
  • Better scalability for FastAPI, Django Async, and other async frameworks.
Example API:
async def stream_users():
    conn = await asyncpg.connect(...)
    
    async with conn.transaction():  # Ensures rollback on failure
        async for row in conn.cursor("SELECT * FROM users"):
            print(row)  # Process each row asynchronously
    
    await conn.close()

asyncio.run(stream_users())

### Describe alternatives you've considered

- asyncio.to_thread() → Still uses blocking I/O and threads, increasing overhead.
- aioodbc → Uses a thread pool, not true async, leading to performance bottlenecks.
- Custom Thread Management → Adds complexity and does not scale well under high concurrency.

### Additional context

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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.

Đánh giá

Issue này chưa được đánh giá.

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.