简体   繁体   English

AS/400 DB2 逻辑文件与表索引

[英]AS/400 DB2 Logical File vs Table Index

I'm coming from a MSSQL background, and when I ask people at my company if they've created Indexes on certain columns they'll say yes but point me to these things call Logical Files.我来自 MSSQL 背景,当我问我公司的人是否在某些列上创建了索引时,他们会说是,但指向我这些称为逻辑文件的东西。

In the iSeries Navigator these Logical Files show up under the 'Views' category.在 iSeries Navigator 中,这些逻辑文件显示在“视图”类别下。 When I click the 'Indexes' category nothing is there, leading me to believe that there are actually no Indexes created on any columns, at least as I understand them.当我单击“索引”类别时,什么都没有,这让我相信实际上没有在任何列上创建索引,至少据我了解。 A Logical File appears to be a View sorted by certain columns.逻辑文件似乎是按某些列排序的视图。

So my question is, are Logical Files and Indexes (indexes in the MSSQL sense) the same thing?所以我的问题是,逻辑文件和索引(MSSQL 意义上的索引)是一回事吗?

While the previous answers aren't necessarily wrong , they don't give the complete picture.虽然以前的答案不一定是错误的,但它们并没有给出完整的画面。

See, there are two types of 'Logical Files' - keyed and unkeyed.看,有两种类型的“逻辑文件”——键控和非键控。

  1. Unkeyed logical files are indeed equivalent to a view, and will not act as an index.无键逻辑文件确实相当于一个视图,并且不会充当索引。
  2. Keyed logical files are equivalent to an index (from what I remember, they're actually implemented in the same way in the underlying system).键控逻辑文件相当于一个索引(据我记得,它们实际上在底层系统中以相同的方式实现)。 These will act as you expect for an index.这些按照您对索引的期望运行。

All logical files, keyed or not, actually show up in iSeries Navigator as views (I think only 'actual' - SQL - indices show up as indices).所有逻辑文件,无论是否键入,实际上在 iSeries Navigator 中显示为视图(我认为只有“实际” - SQL - 索引显示为索引)。

I'm... not actually sure how to find out if a logical file is keyed from Navigator.我...实际上不确定如何确定逻辑文件是否从 Navigator 键入。 And on the iSeries, my company has a (what I assume to be) custom command to show the various logical files (and their keys) for a given physical file (indices show up too).在 iSeries 上,我的公司有一个(我假设是)自定义命令来显示给定物理文件的各种逻辑文件(及其键)(索引也显示)。 However, keyed column are pretty easy to spot on a logical file definition - have some of your AS/400 buddies show you the definitions, and what to look for.但是,在逻辑文件定义中很容易发现键控列 - 让您的一些 AS/400 伙伴向您展示定义以及要查找的内容。

IBM DB2 documentation : IBM DB2 文档

From the perspective of the SQL interface, logical files are identical to views and indexes.从 SQL 接口的角度来看,逻辑文件等同于视图和索引。

There's also this article "SQL indexes and native I/O – no contradiction (2016)" which talks about the differences between "DDS-keyed logical files" and "SQL indexes".还有这篇文章 “SQL 索引和本机 I/O——没有矛盾(2016)” ,它讨论了“DDS 键控逻辑文件”和“SQL 索引”之间的区别。 Note: logical files are part of DDS, they are accessed via "native I/O".注意:逻辑文件是 DDS 的一部分,它们通过“本机 I/O”访问。 "DDS is an outdated technology" though. “DDS 是一种过时的技术”。

Logical Files combine the features of both Views (column selection and table joining) and Indexes (row ordering).逻辑文件结合了视图(列选择和表连接)和索引(行排序)的特性。 They usually function as an Index but do show up as a View in Navigator.它们通常将 function 作为索引,但在导航器中显示为视图。 As a side note a Physical File (not table) can also have an Index.作为旁注,物理文件(不是表)也可以有一个索引。

SQL Tables, Views and Indexes are implemented in DB2 for iSeries using Physical and Logical Files. SQL 表、视图和索引在 iSeries 的 DB2 中使用物理和逻辑文件实现。 The primary difference is when the database checks data integrity.主要区别在于数据库何时检查数据完整性。 It's checked on write for Tables and checked on read for Files.它在写入时检查表并在读取时检查文件。 You can put trash data into a File but not into a Table.您可以将垃圾数据放入文件中,但不能放入表中。

There are actually many tiny differences between SQL created indexes/views and logical files created via DDS (that's the way of writing source files for your logical files (LF) and compiling them to LF-Objects). SQL 创建的索引/视图和通过 DDS 创建的逻辑文件之间实际上存在许多细微差别(这是为逻辑文件 (LF) 编写源文件并将它们编译为 LF 对象的方式)。

So are they the same thing?那么它们是同一个东西吗? That's a definete no there.那是绝对没有的。 But there are very similiar things and in most cases you can use either.但也有非常相似的东西,在大多数情况下你都可以使用。 It's possible that you will never experience any difference, but it's also possible, that one day you stand before an unexplainable situation, because of the differences.有可能你永远不会体验到任何差异,但也有可能,有一天你会因为这些差异而站在一个无法解释的情况面前。 Here are some differences that I have learned so far (and I remember right now).以下是我迄今为止学到的一些差异(我现在记得)。 (I'll talk about LFs -- that's logical files -- and PFs (Physical Files) here. A PF is more or less what you would call a table in SQL, but like with LFs and indices/views, I would not call them the same) (我将在这里讨论 LF——这是逻辑文件——和 PF(物理文件)。PF 或多或少就是你在 SQL 中所说的表,但就像 LF 和索引/视图一样,我不会调用他们一样)

  • LFs can have select/omit statements, which filter which rows of the PF. LF 可以有选择/省略语句,这些语句过滤 PF 的哪些行。 Be careful with those!小心那些! Not only are they often confusing, but they can also have significant impact on your SQL-Queries.它们不仅经常令人困惑,而且还会对您的 SQL 查询产生重大影响。 Such LFs are ignored by the modern query optimizer (SQE) and can even lead to the SQE not being used at all, only because there exist (depending on your SQL-configuration).现代查询优化器 (SQE) 会忽略此类 LF,甚至可能导致根本不使用 SQE,只是因为存在(取决于您的 SQL 配置)。 You can normally get the same behaviour with an sorting index and a select.您通常可以使用排序索引和 select 获得相同的行为。
  • LFs can share data pathes (LF A having index col1, col2, col3 and LF B having index col1, col2, col4 should share the indexing afaik), sql-indices don't do that (but that advantage is supposed to be not as important as the next disadvantage) LF 可以共享数据路径(具有索引 col1、col2、col3 的 LF A 和具有索引 col1、col2、col4 的 LF B 应该共享索引 afaik),sql-indices 不这样做(但这个优势应该不是重要作为下一个缺点)
  • Indices can have a larger page size.索引可以有更大的页面大小。 From what I know, that can make a differnce on huge tables).据我所知,这可以在巨大的桌子上有所作为)。
  • Indices and LFs might act differently when you rename an PF and recrate it from its DDS source.当您重命名 PF 并从其 DDS 源重新创建它时,索引和 LF 的行为可能会有所不同。 Indices should stay on the renamed object, while LFs should refer to the new object with the old name索引应保留在重命名的 object 上,而 LF 应使用旧名称引用新的 object

These differences are related to the fact, that IBMs DB2/400-system was created a long time ago, when noone was talking about SQL and developed ever since.这些差异与 IBM 的 DB2/400 系统是很久以前创建的,当时没有人谈论 SQL 并从那时起开发。 But since SQL became important, IBM also introduced SQL-support for their well used DB.但由于 SQL 变得重要,IBM 还为其使用良好的数据库引入了 SQL 支持。 So indices/views need to support the stuff, SQL requires them to.所以索引/视图需要支持这些东西,SQL 需要它们。 LFs on the other hand must remain downward compatible with the AS/400s history.另一方面,LF 必须与 AS/400 的历史保持向下兼容。 Those differ.那些不同。 And thus, they cannot be the same without dropping support for one.因此,如果不放弃对其中一个的支持,它们就不可能相同。 But they try to come pretty close.但他们试图接近。

Came across this discussion while looking for something else, so thought I would just add a contribution, too.在寻找其他东西时遇到了这个讨论,所以我想我也会添加一个贡献。 PFs and LFs are usually referred to as "native files" due to the fact that they were born with this system ancestor (S/38, not sure if even before), whereas tables/views were introduced later with SQL. PF 和 LF 通常被称为“本机文件”,因为它们是与这个系统祖先一起诞生的(S/38,甚至在之前都不确定),而表格/视图是后来在 SQL 中引入的。 Though nowadays SQE considers both PFs/LFs and tables/views in optimization process, another huge difference among the two is that while both can be used in any SQL statements, even if embedded in compiled programmes, only PFs/LFs can be used native in compiled programmes.虽然现在 SQE 在优化过程中同时考虑 PFs/LFs 和表/视图,但两者之间的另一个巨大区别是,虽然两者都可以在任何 SQL 语句中使用,即使嵌入在编译程序中,也只有 PFs/LFs 可以在本地使用编译的程序。 Considering compiled programmes, changes in PFs/LFs record formats imply rebinding/recompiling process, while there is no need of it in case of tables/views changes, unless they are referred to from outside SQL statement.考虑到已编译的程序,PFs/LFs 记录格式的更改意味着重新绑定/重新编译过程,而在表/视图更改的情况下不需要它,除非它们从 SQL 语句之外引用。

Came across this discussion while looking for something else, so thought I'd contribute.在寻找其他东西时遇到了这个讨论,所以我想我会做出贡献。 A keyed logical file does provide the functionality of an index.带键的逻辑文件确实提供了索引的功能。 However, indexes perform better than logical files, the query optimizer in DB2 for IBM i is more likely to use the SQE (SQL query engine) rather than the older and less efficient CQE ("classic" query engine) to optimize the query if it can use an index.但是,索引的性能优于逻辑文件,DB2 for IBM i 中的查询优化器更有可能使用 SQE(SQL 查询引擎)而不是旧的和效率较低的 CQE(“经典”查询引擎)来优化查询,如果它可以使用索引。 By default, indexes have a larger page size than logical files, which helps with performance.默认情况下,索引的页面大小比逻辑文件大,这有助于提高性能。 In more recent releases of the IBM i operating system, the page size of a logical file can be specified, so that advantage of indexes isn't important as previously.在 IBM i 操作系统的最新版本中,可以指定逻辑文件的页面大小,因此索引的优势不像以前那样重要。 The strategic direction of IBM is to concentrate database performance improvement efforts on the newer SQL DDL defined database objects (tables, indexes, etc.) and to ignore the older legacy DDS defined objects (physical and logical files.) IBM 的战略方向是将数据库性能改进工作集中在较新的 SQL DDL 定义的数据库对象(表、索引等)上,而忽略旧的 DDS 定义的对象(物理和逻辑文件)。

This PDF from IBM which explains the indexing methods in DB2 was helpfull for me in order to understand differences between tables created using SQL or as physical files on AS400 systems.这个来自 IBM 的 PDF 解释了 DB2 中的索引方法对我很有帮助,以便了解使用 SQL 创建的表或作为 AS400 系统上的物理文件之间的差异。

IBM DB2 for i indexing methods and strategies IBM DB2 for i 索引方法和策略

According to this description , an AS/400 DB2 Logical File is called a view in most other relational databases.根据此描述,在大多数其他关系数据库中,AS/400 DB2 逻辑文件称为视图。 I'd have to say that I don't think a logical file is the same as an index.我不得不说我不认为逻辑文件与索引相同。

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

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