简体   繁体   中英

Can i create “logical files” in AS400 using sql?

I need to create as400 "logical files".

my app connects to the db with jdbc.

Is it possible to create "logical files" with sql statements ?

If yes I would appreciate a sample statement.

thanks

I suggest making use of the CREATE INDEX SQL command from the green-screen STRSQL command. Then you can prompt it. Here is an example of CREATE INDEX that let me query a 16 gigabyte file much faster. For this example, the physical file was the results of a database monitor than ran for a week:

CREATE INDEX QGPL.QZG0000016_QUERYJOB ON QGPL.QZG0000016
(QQJNUM ASC, QQUSER ASC, QQJOB ASC, QQUCNT ASC, QQRID ASC, QQI5 ASC)

The index itself took a long time to create, but subsequent queries based on the index were very fast.

If you need to join multiple tables, plan ahead. Know the fields you will use to join the tables and create indexes against the joined tables. You'll get the performance increase you're looking for. For an example, let's make up a query to show the items ordered by a customer:

SELECT ORDETAIL.ITEM_NAME, ORDETAIL.QUANTITY, ORHEADER.SHIPDATE
FROM ORHEADER
INNER JOIN ORDETAIL ON ORDETAIL.ORDERID = ORHEADER.ORDERID
WHERE ORHEADER.CUST_NUM = 123456

You would make the following indexes, if they didn't already exist:

CREATE INDEX DATALIB.ORHEADER_BY_CUSTOMER ON DATALIB.ORHEADER (CUST_NUM ASC, ORDERID)
CREATE INDEX DATALIB.ORDETAIL_BY_ORDER ON DATALIB.ORDETAIL (ORDERID)

If you need to create a logical file select/omit criteria, then you need to create a view. A view is not an index, though, and you can't mix an index and a view like you can with a keyed logical with select/omits. For that, a DDS spec is still the best.

This will help if you are trying to an order by on your view, but will not really help if you have a performance issue.

Sample of data basetable :

A 
B 
C 
A 
A 
A 

Query:

create view myview1  as                   
select lib                                
from(                                     
  SELECT rank() over(order by lib), lib   
FROM basetable) a   

Sample of data from myview1

A 
A 
A 
A 
B 
C 

To achieve much of the same effect, I've created database views over all the tables in an AS/400 DB2, mapping more understandable names to the physical ones. I don't think views are logical files, but I'm just a user of said AS/400 and know exactly as much about it as needed to interact with the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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