Hi Gary,
I'd normally start with what the manual says. However the Informix manual doesn't seem to have much to say on about where any implicit indices go. I can only find:
"You can specify a dbspace for the table that is different from the storage location for the database, or fragment the table among dbspaces, or among named fragments in one or more dbspaces.
"If you specify no IN clause nor fragmentation scheme, the new table is stored in the same dbspace where the current database is stored."
Since it's not explicitly documented what the behaviour should be for related indices it is difficult to raise it as a bug. (Unless you can find a description elsewhere in the manual that I have missed.)
Personally I avoid this inline syntax and have gone as far to write scripts to manipulate schema files to remove it for primary keys and foreign keys for the reason you have found. I tend to think this syntax is there for compatibility; it certainly reduces your level of control and on large busy systems this kind of thing starts to become very important.
Lurking in the background is the problem that a unique index of any kind, i.e. primary key or unique constraint, cannot follow the table schema unless the lead key is the same as the range column. While your case seems to have a sensible solution, if you were to add "UNIQUE (fk_col)" to your CREATE TABLE statement this index would have to be detached. Where does the index get placed then? It is not clear to me that it should go in any of the dbspaces listed for the intervals or partition "p0". So it goes in the default dbspace.
I support the idea behind an RFE but I think it would need to cover the two cases being discussed:
- A unique index or PK which has a lead key the same as the range column.
- A unique index or PK which does not.
Ben.
------------------------------
Benjamin Thompson
------------------------------
Original Message:
Sent: Thu July 09, 2020 12:46 PM
From: Gary Andrus
Subject: Index Placement for PK and FK
Running Informix 12.10.FC10 in a Linux environment.
I've looked through a lot of documentation, but haven't found anything about index storage with this specific situation: fragmented table, different page size than database, and implicit index on PK and/or FK.
I have something similar to the following table created in a database that defaults to a 2K dbspace, but the table is fragmented on multiple 8K dbspaces:
CREATE TABLE my_8k_tbl
(
pk_col BIGSERIAL not null,
fk_col INTEGER not null,
ix1_col INTEGER not null,
ix2_col datetime year to minute,
PRIMARY KEY (pk_col) CONSTRAINT pk_col_constr
)
FRAGMENT BY RANGE(pk_col) INTERVAL(12345) STORE IN (8K1, 8K2)
PARTITION p0 VALUES < 12345 IN 8K1
EXTENT SIZE...
;
CREATE INDEX ix1 ON my_8k_tbl (ix1_col) using btree;
CREATE INDEX ix2 ON my_8k_tbl (ix2_col) using btree;
ALTER TABLE my_8k_tbl ADD CONSTRAINT (FOREIGN KEY (fk_col) REFERENCES fk_tbl);
The PK index and the FK index are implicitly defined and are created on the 2K space of the database, not the 8K space(s) of the table. The ix1 and ix2 indexes are both on the 2 8K dbspaces and fragmented just as the table.
As shown above, should the PK and FK indexes be on the 2K page or the 8K page? Do the PK and FK indexes need to be created first to store them on the 8K dbspaces with the table? If so, should this be an RFE to put the implicits with the table, not the db? Or does everyone expect them to go with the DB, not the table?
This e-mail may contain confidential or privileged information. If you believe you have received this e-mail in error, please notify the sender by reply e-mail and then delete this e-mail immediately.
#Informix