Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Informix > Setting Serial downwards

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-06-03, 11:46
Bob Elliot Bob Elliot is offline
Registered User
 
Join Date: Jan 2003
Posts: 6
Setting Serial downwards

The Alter Table .. modify .. (.. serial(?)) statement allows the next value of a serial to be changed.

This cannot be moved below the maximum value it has been set to on a table - even if the higher serials have been deleted.

We have rather a large table where the serial has been set to a ridiculously large value (suspect an insert with corrupt value from inside an esql/c program).

Is there any way to set the next value to a lower value - other than by unloading, dropping and reloading the table ?

How is the constraint which forces the serial number upwards implemented ?
Reply With Quote
  #2 (permalink)  
Old 01-07-03, 08:03
Roelwe Roelwe is offline
Registered User
 
Join Date: Aug 2002
Location: Belgium
Posts: 534
You could change the column to an integer datatype.
Set the values as you wish an then alter the table to reset the column to a serial datatype. If you have an index on the serial column, you might consider to drop it first and recreate it afterwards.
__________________
rws
Reply With Quote
  #3 (permalink)  
Old 01-07-03, 09:30
Roelwe Roelwe is offline
Registered User
 
Join Date: Aug 2002
Location: Belgium
Posts: 534
> Nice One,
> It's not the first time I've met this problem.

> We tried on a development box - 170K rows - took about a minute.

> Few questions
> Didn't drop the index - any risk there ?
> The conversion to integer was virtually instantaneous - does this
> simply involve changing a system table ?
> The conversion to serial was more time consuming - was it recreating > the maximum serial ?
> Any need to lock the table or stop logging ?

> The target table has around 14 Million rows and as we would like to
> keep any outage to a minimum we would rather avoid dropping and
> recreating the index if that is safe.

You don't have to drop/recreate the index.
It is faster to drop and recreate it.

The conversion is very easy. serial is an int8 datatype, so no conversion needed. Informix just creates a new version of the table to have the least downtime as possible. Once you have lots of time you could reset the table to version 1, but that might take some time.

The conversion to serial was more time consuming because he had to check for any duplicates. So once you converted to integer, recreate the index and than convert back to serial.
Just make sure you don't create a long transaction. That might be a disaster. make sure you have enough log space, or just tur off logging (not really the best solution).

Anyway, goodluck!
__________________
rws
Reply With Quote
  #4 (permalink)  
Old 01-07-03, 09:36
Bob Elliot Bob Elliot is offline
Registered User
 
Join Date: Jan 2003
Posts: 6
Is there any implication to not setting the version of the table back to 1 ?
Reply With Quote
  #5 (permalink)  
Old 01-07-03, 10:32
Roelwe Roelwe is offline
Registered User
 
Join Date: Aug 2002
Location: Belgium
Posts: 534
Just a little performance.
And when you do a migration, that's the first thing it does. So your migration might take some more time. This is actually one of the biggest time-consuming issues of a migration.
Hope it helps.
__________________
rws
Reply With Quote
  #6 (permalink)  
Old 01-07-03, 11:00
Roelwe Roelwe is offline
Registered User
 
Join Date: Aug 2002
Location: Belgium
Posts: 534
Talking

> Query on Versions
>Hi Roelwe,
>I date back to earlier versions of Informix (4) where the table was >converted (I think) when you changed the type of a column.

>I have also (briefly) worked with Ingres.
>In Ingres 2 (if I remember correctly) a table has versions.
>Each page on the database carries the version which applies to that >page.
>If you change the table structure (options were limited) this only >changed the header of the table.
>Each page was then converted between versions as it was updated.

>Have Informix implemented this - if so from what version and where >can I read up on it ?

>Sorry to be a pain - but I'm curious.


No problem in beiing curious.
informix and Ingres merged their technology and it resulted in (I think it was ) version 5.
The table versioning of Informix is implemented since then. (More than 10 years) Oracle did it 2 years ago ...
I think you should find it somewhere in the documentation. It is available on the web.
__________________
rws
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On