由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 老印给我的一个Challenge
相关主题
问个数据库问题cursor可以往回找否??
ask for help with a simple query!!!how to make this query
MS SQL database engineer(sr)ONSITE 面试该如何准备?如何在数据库中进行复杂查询, 但不把中间结果放到程序内存
2 SQL SERVER Sr SQL Programmer positions (转载)有关oracle form的新手问题
德州招SQL Developer请问sql server里面怎么输出变量到文本文件?
开班了怎么写个query 把输出变成横排.
求被“开班”培养!Best way to fetch dynamic rows of data block from recordset
想做几个SQL development的projectsql server问题, 不同数据库之间表拷贝,大数据量
相关话题的讨论汇总
话题: cursor话题: col话题: sql话题: table话题: dest
进入Database版参与讨论
1 (共1页)
b******g
发帖数: 81
1
老印做数据库的特点:
爱用Stored Procedure
爱从一个表导到另一个表(从不吝惜用Temporary Table)
爱用Dynamic SQL
现在组里的老印和我同做一个项目,有一个问题不知道怎么解决:
Table Source 到 Table Dest_xxx 导数据
限制条件:
1、不用SSIS
2、Dest_xxx可变,具体表名从另外一个设置表 Table Config 里查
3、设置发生变化 Dest_xxx 后,只需要改设置的数据,不需要修改程序
老印主张用Dynamic SQL,我想避免用Dynamic SQL(主要从Performance方面考虑)。
现在想请教大牛们,有什么办法没有?
a9
发帖数: 21638
2
dynamic sql相比导表来讲,性能没什么损失吧?

【在 b******g 的大作中提到】
: 老印做数据库的特点:
: 爱用Stored Procedure
: 爱从一个表导到另一个表(从不吝惜用Temporary Table)
: 爱用Dynamic SQL
: 现在组里的老印和我同做一个项目,有一个问题不知道怎么解决:
: Table Source 到 Table Dest_xxx 导数据
: 限制条件:
: 1、不用SSIS
: 2、Dest_xxx可变,具体表名从另外一个设置表 Table Config 里查
: 3、设置发生变化 Dest_xxx 后,只需要改设置的数据,不需要修改程序

b******g
发帖数: 81
3
If it is just one dynamic SQL, the recompile time is not an issue.
The thing is the design is using a cursor, looping through each record.
Inside the loop, there is the dynamic SQL (INSERT INTO). Then every time
calling the dynamic SQL in the loop, it is recompiled - the recompile time
will multiply the number of records.
For thousands of records, the performance might be acceptable, but for
millions level, it will be a big overhead.

【在 a9 的大作中提到】
: dynamic sql相比导表来讲,性能没什么损失吧?
j*****n
发帖数: 1781
4
I assume your cursor is only for retrieving the table names from the
configure table. Then it should be fine since no million of rows there.
Just curious, why SSIS cannot be used?

【在 b******g 的大作中提到】
: If it is just one dynamic SQL, the recompile time is not an issue.
: The thing is the design is using a cursor, looping through each record.
: Inside the loop, there is the dynamic SQL (INSERT INTO). Then every time
: calling the dynamic SQL in the loop, it is recompiled - the recompile time
: will multiply the number of records.
: For thousands of records, the performance might be acceptable, but for
: millions level, it will be a big overhead.

B*****g
发帖数: 34098
5
不明白,为什么每个record都要call一下?

【在 b******g 的大作中提到】
: If it is just one dynamic SQL, the recompile time is not an issue.
: The thing is the design is using a cursor, looping through each record.
: Inside the loop, there is the dynamic SQL (INSERT INTO). Then every time
: calling the dynamic SQL in the loop, it is recompiled - the recompile time
: will multiply the number of records.
: For thousands of records, the performance might be acceptable, but for
: millions level, it will be a big overhead.

b******g
发帖数: 81
6
Negative. The cursor is for retrieving at least 100K records.
If I were the original designer, I would have chosen SSIS. Now it is the
halfway, with the design approved, no one would want to go backwards.

【在 j*****n 的大作中提到】
: I assume your cursor is only for retrieving the table names from the
: configure table. Then it should be fine since no million of rows there.
: Just curious, why SSIS cannot be used?

b******g
发帖数: 81
7
导表过程中先要做Validation和Data Cleaning,然后才是INSERT到Dest_xxx表。用
CURSOR从编程角度看,逻辑更简单。要CURSOR LOOP,自然是要每个Record都Call一下。
另外,我想挑战一下这个Dest_xxx的设计。设计估计是老印做的,他告诉我的是为了系
统扩容后,不同子系统使用不同的Dest_xxx表,可以减少子系统相互之间Lock。
如果没有了动态的Dest_xxx,Dynamic SQL 自然就不需要了。

【在 B*****g 的大作中提到】
: 不明白,为什么每个record都要call一下?
B*****g
发帖数: 34098
8
先做validation,data clean.
然后把valid的record再insert

下。

【在 b******g 的大作中提到】
: 导表过程中先要做Validation和Data Cleaning,然后才是INSERT到Dest_xxx表。用
: CURSOR从编程角度看,逻辑更简单。要CURSOR LOOP,自然是要每个Record都Call一下。
: 另外,我想挑战一下这个Dest_xxx的设计。设计估计是老印做的,他告诉我的是为了系
: 统扩容后,不同子系统使用不同的Dest_xxx表,可以减少子系统相互之间Lock。
: 如果没有了动态的Dest_xxx,Dynamic SQL 自然就不需要了。

j*****n
发帖数: 1781
9
Validation和Data Cleaning can be done in staging table and using queries
instead of cursors. Most of programming in cursor can be turned to queries,
at least in my life.
CURSOR从编程角度看,逻辑更简单? No, that's only mean that you are not a
complete DB guy yet... :-)

下。

【在 b******g 的大作中提到】
: 导表过程中先要做Validation和Data Cleaning,然后才是INSERT到Dest_xxx表。用
: CURSOR从编程角度看,逻辑更简单。要CURSOR LOOP,自然是要每个Record都Call一下。
: 另外,我想挑战一下这个Dest_xxx的设计。设计估计是老印做的,他告诉我的是为了系
: 统扩容后,不同子系统使用不同的Dest_xxx表,可以减少子系统相互之间Lock。
: 如果没有了动态的Dest_xxx,Dynamic SQL 自然就不需要了。

B*********L
发帖数: 700
10
Table Source 到 Table Dest_xxx
既然Source不变,我会只create一个Dest table,但是增加一个 xxx column, xxx
column 加index
相关主题
开班了cursor可以往回找否??
求被“开班”培养!how to make this query
想做几个SQL development的project如何在数据库中进行复杂查询, 但不把中间结果放到程序内存
进入Database版参与讨论
b******g
发帖数: 81
11
CURSORs surely can be turned into queries. Validation and Data cleaning is
for each column. The way I can think of writing the query is:
=======================================================
INSERT INTO Dest_xxx (COL_A, COL_B,...)
SELECT ufn_CLEAN(COL_A), ufn_CLEAN(COL_B),...
FROM Source
WHERE ufn_VAL(COL_A)=true AND ufn_VAL(COL_B)=true AND ...
=======================================================
There is no index on COL_A, COL_B,...
The above SELECT statement is doing a full table scan. I

【在 j*****n 的大作中提到】
: Validation和Data Cleaning can be done in staging table and using queries
: instead of cursors. Most of programming in cursor can be turned to queries,
: at least in my life.
: CURSOR从编程角度看,逻辑更简单? No, that's only mean that you are not a
: complete DB guy yet... :-)
:
: 下。

b******g
发帖数: 81
12
Will propose that to the Indian guy.

【在 B*********L 的大作中提到】
: Table Source 到 Table Dest_xxx
: 既然Source不变,我会只create一个Dest table,但是增加一个 xxx column, xxx
: column 加index

B*****g
发帖数: 34098
13
任何一个query都是通过cursor实现的,如果没记错是汤姆凯特说的

column 的。 这样的话,我能想到的改写就成了这样:
吧。
loop比起来,速度上没什么优势吧。
queries

【在 b******g 的大作中提到】
: Will propose that to the Indian guy.
j*****n
发帖数: 1781
14
who told you that table scan will be the same performance as cursor loop?
give a try man, i bet your query is still much faster. that's the power of
SQL engine.
btw, i still believe SSIS is the best solution for your case. these ETL
steps can be done within one single data flow task. of course, by doing so
your server's memory should be large enough...

column 的。 这样的话,我能想到的改写就成了这样:
吧。
loop比起来,速度上没什么优势吧。

【在 b******g 的大作中提到】
: Will propose that to the Indian guy.
b******g
发帖数: 81
15
我在另外一个Application已经做过这种改写。情况和这次类似,都是对所有的Columns
进行Validation,然后做Data Clean,导表。我当时非常希望CURSOR LOOP改写成Static
Query后速度有很大提高,然而结果却是基本没什么变化(if you wanna bet, you
still can)。
SSIS的确是我对ETL这类Application的首选工具,不过技术路线可不是我定的。

【在 j*****n 的大作中提到】
: who told you that table scan will be the same performance as cursor loop?
: give a try man, i bet your query is still much faster. that's the power of
: SQL engine.
: btw, i still believe SSIS is the best solution for your case. these ETL
: steps can be done within one single data flow task. of course, by doing so
: your server's memory should be large enough...
:
: column 的。 这样的话,我能想到的改写就成了这样:
: 吧。
: loop比起来,速度上没什么优势吧。

b******g
发帖数: 81
16
SQL Engine是不是真这么实现Query我可不知道了。以后有机会可以挖一挖。

【在 B*****g 的大作中提到】
: 任何一个query都是通过cursor实现的,如果没记错是汤姆凯特说的
:
: column 的。 这样的话,我能想到的改写就成了这样:
: 吧。
: loop比起来,速度上没什么优势吧。
: queries

b******g
发帖数: 81
17
这个帖子的问题估计可以用CURSOR到Static Query的改写提高性能:
http://www.mitbbs.com/article_t/Database/31146499.html
不远,就在我的帖子下面一点。还有包子!

【在 j*****n 的大作中提到】
: who told you that table scan will be the same performance as cursor loop?
: give a try man, i bet your query is still much faster. that's the power of
: SQL engine.
: btw, i still believe SSIS is the best solution for your case. these ETL
: steps can be done within one single data flow task. of course, by doing so
: your server's memory should be large enough...
:
: column 的。 这样的话,我能想到的改写就成了这样:
: 吧。
: loop比起来,速度上没什么优势吧。

k**0
发帖数: 19737
18
使用ROW_NUMBER function可以代替CURSOR, 一个QUERY就OK了.
给包子吧.

【在 b******g 的大作中提到】
: 这个帖子的问题估计可以用CURSOR到Static Query的改写提高性能:
: http://www.mitbbs.com/article_t/Database/31146499.html
: 不远,就在我的帖子下面一点。还有包子!

y****w
发帖数: 3747
19
re。访问query结果转换到数据库内部都是类似cursor的样子,查一下这时候表/行上的锁就更清楚了。
只是此cursor非彼cursor。坚决避免不必要的cursor编程。

【在 B*****g 的大作中提到】
: 任何一个query都是通过cursor实现的,如果没记错是汤姆凯特说的
:
: column 的。 这样的话,我能想到的改写就成了这样:
: 吧。
: loop比起来,速度上没什么优势吧。
: queries

1 (共1页)
进入Database版参与讨论
相关主题
sql server问题, 不同数据库之间表拷贝,大数据量德州招SQL Developer
best practices for sql developer开班了
为何query这么慢?求被“开班”培养!
关于not closed cursor的请教想做几个SQL development的project
问个数据库问题cursor可以往回找否??
ask for help with a simple query!!!how to make this query
MS SQL database engineer(sr)ONSITE 面试该如何准备?如何在数据库中进行复杂查询, 但不把中间结果放到程序内存
2 SQL SERVER Sr SQL Programmer positions (转载)有关oracle form的新手问题
相关话题的讨论汇总
话题: cursor话题: col话题: sql话题: table话题: dest