pySQLite插入速度 [英] pySQLite Insert speed
问题描述
我在这个论坛上看到下面的SQL编码(A)优先于
(B),但我发现(B)更快(20-40%更快)
(A)
sqla =''插入DTABLE1值(%d,%d,%d,%f)''%值
curs.execute(sqla)
(B)
pf =''?,?,?,?''
sqlxb =''INSERT INTO DTABLE2 VALUES(%s)''%pf
curs.execute(sqlxb,values)
关于为什么(A)较慢的任何直觉?
I hav read on this forum that SQL coding (A) below is preferred over
(B), but I find (B) is much faster (20-40% faster)
(A)
sqla= ''INSERT INTO DTABLE1 VALUES (%d, %d, %d, %f)'' % values
curs.execute(sqla)
(B)
pf= ''?, ?, ?, ?''
sqlxb= ''INSERT INTO DTABLE2 VALUES ( %s ) '' % pf
curs.execute( sqlxb, values )
Any intution on why (A) is slower?
推荐答案
2008年2月28日星期四19:35:03 -0800(太平洋标准时间),mdboldin写了
On Thu, 28 Feb 2008 19:35:03 -0800 (PST), mdboldin wrote
我在这个论坛上看到下面的SQL编码(A)优先于
(B),但我发现(B) )更快(20-40%更快)
(A)
sqla =''插入DTABLE1值(%d, %d,%d,%f)''%值
curs.execute(sqla)
(B)
pf =''?,?,?, ?''
sqlxb =''INSERT INTO DTABLE2 VALUES(%s)''%pf
curs.execute(sqlxb,values)
>
关于为什么(A)变慢的任何直觉?
I hav read on this forum that SQL coding (A) below is preferred over
(B), but I find (B) is much faster (20-40% faster)
(A)
sqla= ''INSERT INTO DTABLE1 VALUES (%d, %d, %d, %f)'' % values
curs.execute(sqla)
(B)
pf= ''?, ?, ?, ?''
sqlxb= ''INSERT INTO DTABLE2 VALUES ( %s ) '' % pf
curs.execute( sqlxb, values )
Any intution on why (A) is slower?
我对(B)的唯一问题是它应该是这样的:
sqlxb =''INSERT INTO DTABLE2 VALUES(?,?,?,?)''
curs.execute(sqlxb,values)
除此之外,(B)优于(一个)。 (B)
中使用的参数绑定不仅在许多数据库上更快,而且更安全。例如,请参阅
http:/ /informixdb.blogspot.com/2007/...in-blanks.html 对于某些
深入解释为什么参数绑定比字符串更好
格式化执行带有变量值的SQL查询。
HTH,
-
Carsten Haese
http://informixdb.sourceforge.net
My only problem with (B) is that it should really be this:
sqlxb= ''INSERT INTO DTABLE2 VALUES (?, ?, ?, ?)''
curs.execute( sqlxb, values )
Apart from that, (B) is better than (A). The parameter binding employed in (B)
is not only faster on many databases, but more secure. See, for example,
http://informixdb.blogspot.com/2007/...in-blanks.html for some
in-depth explanations of why parameter binding is better than string
formatting for performing SQL queries with variable values.
HTH,
--
Carsten Haese
http://informixdb.sourceforge.net
(B)优于(A)。 (B)
(B) is better than (A). The parameter binding employed in (B)
中使用的参数绑定不仅在许多数据库上更快,而且更安全。
is not only faster on many databases, but more secure.
例如,参见 http://informixdb.blogspot.com/2007/07/filling-in-
blanks.html
Thx。这个链接很有帮助,我想我之前已经阅读了类似的东西
- B更快。
所以......我只是从头开始重写了测试代码B更快。我原来的时间肯定有问题。
See, for example,http://informixdb.blogspot.com/2007/07/filling-in-
blanks.html
Thx. The link was helpful, and I think I have read similar things
before-- that B is faster.
So ... I just rewrote the test code from scratch and B is faster. I
must have had something wrong in my original timing.
md ****** @ gmail.com 写道:
>
我在这个论坛上看过下面的SQL编码(A)比
(B)更受欢迎,但我发现(B)更快(20-40%更快)
(A)
sqla =''INSERT INTO DTABLE1 VALUES(%d,%d,%d,%f)''%值
curs.execute(sqla)
(B)
pf =''?,?,?,?''
sqlxb =''INSERT INTO DTABLE2 VALUES(%s)''% pf
curs.execute(sqlxb,values)
任何关于为什么(A)变慢的直觉?
>
I hav read on this forum that SQL coding (A) below is preferred over
(B), but I find (B) is much faster (20-40% faster)
(A)
sqla= ''INSERT INTO DTABLE1 VALUES (%d, %d, %d, %f)'' % values
curs.execute(sqla)
(B)
pf= ''?, ?, ?, ?''
sqlxb= ''INSERT INTO DTABLE2 VALUES ( %s ) '' % pf
curs.execute( sqlxb, values )
Any intution on why (A) is slower?
我觉得你误解了。 (B)*总是*正确的方式来进行参数化的SQL查询。无条件。 (A)样式太容易受到SQL注入攻击了。
-
Tim Roberts, ti ** @ probo.com
Providenza& Boekelheide,Inc。
I think you misunderstood. (B) is *ALWAYS* the proper way of doing
parameterized SQL queries. Unconditionally. The (A) style is way too
vulnerable to SQL injection attacks.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
这篇关于pySQLite插入速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!