By mmilano on
i'd like to programmatically change the field type in the db for a cck field from text to varchar so i can then index it.
i'm wondering if there is a 'proper' way to do this via the cck api somehow, or go off with db alters.
Comments
...
1. If you give your field a "Maximum length" less than 256, CCK uses a varchar for it. You should be able to modify this "Maximum length" for existing fields too, so you don't need to do this programmatically.
2. "BLOB and TEXT columns also can be indexed, but a prefix length must be given." (This prefix thingy is actually used in Drupal for indexing varchar fields as well; e.g. node.type)
Views2 glossary summary error fixed by change to CCK field type
Thanks for this trick.
On a different but related note, I recently encountered an issue with this and the 'Glossary mode' option of a views argument, and changing the CCK field setting (and thus, underlying MySQL field type) resolved my issue.
What was happenening was that with glossary mode enabled for my CCK LONGTEXT field, I was getting "<NO VALUE>" as the attachment glossary output. After a bit of troubleshooting I figured out my localhost MySQL 5.1 doesn't have the problem but my live MySQL 4.1 does.
I found these bug reports (http://bugs.mysql.com/bug.php?id=38674, http://bugs.mysql.com/bug.php?id=10963) on the MySQL site and tested changing the type of my field to VARCHAR(255) in PHPMyAdmin, which solved the views attachment 'Glossary mode' issue.
Then I found this thread on d.o and realised that CCK does the database field type change according to your CCK field settings, which is much preferred.
Obviously upgrading MySQL is the best option, but if you can't do that easily on your host I hope this info may help someone out.
Thank you!
This is just the information I needed -- changing the max length of my CCK text fields fixed the problem in the views glossary. I can't imagine how much time it would have taken to figure this out if I hadn't seen your post!
Excellent suggestion!!
This was a great suggestion. mySQL was creating a temp tables on the disk even after I increased my tmp_table_size and max_heap_table_size. This was the key to stopping that, and hopefully improving performance a tad...
As you said, after you set the max length of an existing CCK text field to 255 or less, the columns in the database tables are changed to varchar.
Thanks!