vazagothic
Programmer
Hello all,
last week I've started working with VFP9 (after working with 6 & 8) and I am really happy with the product.
I've decided to change the structure of one table, a table which was created a long time ago and has pretty bad structure.
This is the structure of the table:
I decided to convert the existing Character fields (marked with [red]Red[/red]) into new VarChar fields, which hold more flexibility.
Theoretically it should shrink the size of the table by more than 30% (the table is 3.5MB big, there are over 10'000 records in the table, but only 1'300 of them have a value in the [red]emailto[/red] field)
To my surprise, the table didn't shrink at all, to a contrary - it even grew bigger for about 10KB).
I thought, "well - maybe the VarChar field now keeps all the additional spaces" - so I tried the following:
REPLACE ALL emailto WITH ALLTRIM(emailto)
It DIDN't help. I tried copying the content of the table to another one - it didn't help either.
Then I did a small experiment and created two small tables with the same content, but one of them kept the data stored in a CHARACTER field, the other one in VARCHAR field.
Well ..
The CHARACTER Table:
Size: 1'275'329 bytes
and the VarChar table:
Size: 1'280'361 bytes
What the heck ???
I THOUGHT that VarChar was supposed to take LESS space than a CHARACTER field, since it doesn't store the empty spaces at the end.
WAS I SO WRONG ??
Sorry for the long message, but I just cannot imagine VarChar being SO USELESS!
According to VFP9 help:
To include alphanumeric text in fields without including additional padding with spaces or truncating trailing spaces, use the Varchar type. Alphanumeric text can contain letters, numbers, spaces, symbols, and punctuation. The Varchar type also provides a convenient method for mapping SQL Server Varchar types to corresponding Visual FoxPro data types.
last week I've started working with VFP9 (after working with 6 & 8) and I am really happy with the product.
I've decided to change the structure of one table, a table which was created a long time ago and has pretty bad structure.
This is the structure of the table:
Code:
Field Field Name Type Width Dec Index Collate Nulls Next Step
1 ITEM_ID Numeric 10 Asc Machine No
2 STATE_ID Numeric 10 Asc Machine No
[red]3 ITEM_TYPE Character 17 No[/red]
4 DATEIN Date 8 No
5 DUEDATE Date 8 Asc Machine No
[red]6 PERSONRPT Character 30 No[/red]
7 PROB_DESC Memo 4 No
8 PRIORITY_ID Numeric 10 Asc Machine No
9 CLOSED Date 8 No
10 USER_ID Numeric 10 Asc Machine No
11 MODULE_ID Numeric 10 Asc Machine No
12 PRODUCT_ID Numeric 10 Asc Machine No
13 TEST_SCRIP Numeric 10 Asc Machine No
[red]14 KEYWORD1 Character 15 No
15 KEYWORD2 Character 15 No
16 KEYWORD3 Character 15 No[/red]
17 HRS_ESTIMATE.. Numeric 7 2 No
18 VISIBILITY Character 10 No
[red]19 EMAILTO Character 125 No[/red]
20 ADDINFO_ID Numeric 3 No
21 IMPACT Numeric 3 No
22 SCOPE Numeric 3 No
** Total ** 342
I decided to convert the existing Character fields (marked with [red]Red[/red]) into new VarChar fields, which hold more flexibility.
Theoretically it should shrink the size of the table by more than 30% (the table is 3.5MB big, there are over 10'000 records in the table, but only 1'300 of them have a value in the [red]emailto[/red] field)
To my surprise, the table didn't shrink at all, to a contrary - it even grew bigger for about 10KB).
I thought, "well - maybe the VarChar field now keeps all the additional spaces" - so I tried the following:
REPLACE ALL emailto WITH ALLTRIM(emailto)
It DIDN't help. I tried copying the content of the table to another one - it didn't help either.
Then I did a small experiment and created two small tables with the same content, but one of them kept the data stored in a CHARACTER field, the other one in VARCHAR field.
Well ..
The CHARACTER Table:
Code:
CREATE TABLE a (cn [red]C(254)[/red])
FOR I=1 TO 5000
INSERT INTO a (cn) VALUES ("123456789012")
ENDFOR
Size: 1'275'329 bytes
and the VarChar table:
Code:
CREATE TABLE b (cn [red]VarChar(254)[/red])
FOR I=1 TO 5000
INSERT INTO b (cn) VALUES ("123456789012")
ENDFOR
Size: 1'280'361 bytes
What the heck ???
I THOUGHT that VarChar was supposed to take LESS space than a CHARACTER field, since it doesn't store the empty spaces at the end.
WAS I SO WRONG ??
Sorry for the long message, but I just cannot imagine VarChar being SO USELESS!
According to VFP9 help:
To include alphanumeric text in fields without including additional padding with spaces or truncating trailing spaces, use the Varchar type. Alphanumeric text can contain letters, numbers, spaces, symbols, and punctuation. The Varchar type also provides a convenient method for mapping SQL Server Varchar types to corresponding Visual FoxPro data types.