有没有像Parallel CURSOR这样的东西? [英] Is there anything like Parallel CURSOR?

查看:43
本文介绍了有没有像Parallel CURSOR这样的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 CURSOR 进行一些逐行操作.

I am using CURSORs to do some row-by-row operation.

OPEN CURSOR_T

FETCH NEXT FROM ...

WHILE @@FETCH_STATUS = 0
BEGIN
      ... Block begins

      ... Block Inserts results into a table

      ... Block terminates
END

我想知道为什么这不能并行执行,因为行操作是完全隔离的,并且只将一些行插入到另一个表中,并且每一行都分配了自己的 ID,因此没有明显的冲突可能性.

I was wondering why this cannot be executed in parallel as the row operations are completely isolated and only insert some rows into another table and each row has its own ID assigned so there is no obvious possibility of a conflict.

我想知道是否有办法在纯 SQL 中并行化它?

I was wondering if there is a way to parallelize this in pure SQL?

推荐答案

这通常是通过队列来实现的:您选择待办事项"并将它们放入队列中,同时将读取器(处理线程) 正在出列待办事项"并一一处理它们.使用表作为队列是一门艺术,处理通常与激活相关联,并且入队/出队循环实际上是连续的.

This is usually achieved through a queue: you select the 'to do' items and drop them into a queue, and at the same time queue readers (processing threads) are dequeuing the 'to do' items and process them one by one. There is a fine art in using tables as queues, the processing is often associated with activation and the enqueue/dequeue cycle is actually contiguous.

这篇关于有没有像Parallel CURSOR这样的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆