简体   繁体   English

db2 sql字段上第二个主键上的游标选择用于嵌入位置值-无法确定最有效的长期设计

[英]Cursor select on 2nd Primary key on db2 sql field for embedded positional value - Unable to determine most efficient for longterm design

I have a SQL DB2 table where the first two fields are the primary keys (not including the third field which is date/time stamp). 我有一个SQL DB2表,其中前两个字段是主键(不包括第三个字段,它是日期/时间戳)。 The table was designed by another team with the intent to make it generic. 该表是由另一个团队设计的,旨在使其具有通用性。 I was brought into the project after the key value for the second field was coded for when it was inserted onto the table. 在将第二个字段的键值插入表中后对其进行编码后,我进入了项目。 This leads me to this: We now have to do a cursor select with a WHERE clause that includes the first primary key – and then for the second primary key it must be for only when it is a specific value in position 21 for 8 bytes. 这使我想到了这一点:现在,我们必须使用包含第一个主键的WHERE子句来进行游标选择-然后对于第二个主键,仅当它是位置21的8个字节的特定值时,它才必须用于。 (And we will always know what that value will be for the second field.) The second field is a generic 70 byte field (alphanumeric). (而且我们将永远知道第二个字段的值是什么。)第二个字段是一个通用的70字节字段(字母数字)。 My question is should we use a LIKE wildcard for the WHERE clause statement for the second primary field condition or instead a SUBSTR since we know the position of the value? 我的问题是,对于第二个主字段条件,我们应该对WHERE子句语句使用LIKE通配符,还是对子字符串使用SUBSTR,因为我们知道值的位置? I ask because I have done an EXPLAIN yet I do not see a difference between the two (neither does my database analyst). 我问是因为我做了一个解释,但是我没有看到两者之间的区别(我的数据库分析师也没有)。 And this is for a few million records for a 1300 byte long table. 这是一个1300字节长的表的几百万条记录。 However, my concern is volume of the data on the table will grow on various systems. 但是,我担心的是,表上的数据量在各种系统上都会增长。 Therefore performance may become an issue. 因此,性能可能成为问题。 Just right now it is hard to measure the difference between LIKE and SUBSTR. 现在,很难衡量LIKE和SUBSTR之间的差异。 But I would like to do my due diligence and code this for long term performance. 但我想尽职调查并为此编写代码以实现长期性能。 And if there is a third option, please let me know. 如果还有第三种选择,请告诉我。

The CPU difference between a SUBSTR and a LIKE will be minimal. SUBSTRLIKE之间的CPU差异将很小。 What might be more important is the filter factor estimate in the explain. 可能更重要的是解释中的滤波因子估计。 You might want to use a statistical view over the table to help the optimizer here. 您可能希望在表格上使用统计视图来帮助优化器。 In that case the SUBSTR operator will be better as you would include that as a column in the stats view. 在这种情况下, SUBSTR运算符会更好,因为您可以将其作为stats视图中的一列包括在内。

Alternatively, a generated column based on the SUBSTR would also provide the better stats, and you could include the column in an index too. 或者,基于SUBSTR生成的列也将提供更好的统计信息,您也可以将该列包括在索引中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM