Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-11-05 09:54:13

geralt
Member
From: Al otro lado de la pantalla
Registered: 2008-03-27
Posts: 12
Website

MySQL database fields definition.

Yesterday I was trying to optimize the database performance and I saw things that put me in doubt. See an example:

looking ‘textpattern’s table definition we see:

`Annotate` int(2) NOT NULL default ‘0’

About this sentence, two questions:

  1. Why default value of an integer field is a char?
  2. if a parentheses only specify the display with of integer data types (see [1]) why use `int(2)` when we store 0/1 values? Is not better using tynyint(1)?

Thanks for your time and sorry if it’s a silly question :-) ciao.

[1] http://dev.mysql.com/doc/refman/5.5/en/numeric-type-attributes.html

Offline

#2 2013-11-05 10:50:13

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: MySQL database fields definition.

All points are true. Textpattern’s database field definitions are in places wrong; some of which we have resolved in 4.6-dev. Outside from IDs, all integer fields should be tinyints.

Offline

#3 2013-11-05 11:17:15

geralt
Member
From: Al otro lado de la pantalla
Registered: 2008-03-27
Posts: 12
Website

Re: MySQL database fields definition.

Hi Gocom,

where can I find 4.6-dev version’s code?

Offline

#4 2013-11-05 11:23:51

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: MySQL database fields definition.

Nightlies (downloads), git (read-only) and SVN. We’ve done these database structure changes.

Last edited by Gocom (2013-11-05 11:34:22)

Offline

#5 2013-11-05 11:55:26

geralt
Member
From: Al otro lado de la pantalla
Registered: 2008-03-27
Posts: 12
Website

Re: MySQL database fields definition.

Sorry Gocom,

but I don’t see the changes. Neither [1], [2] or [3] had been modified to transfer int(2) to tinyint (or an other integer field adjustment). Sorry for my blindness :-)

[1] https://github.com/textpattern/textpattern/blob/1f284cf1d3b2a9b34443f156997d47161e4f139a/textpattern/update/_to_4.6.0.php
[2] http://textpattern.googlecode.com/svn/development/4.x/textpattern/update/_to_4.6.0.php
[3] http://textpattern.googlecode.com/svn/development/4.x/textpattern/setup/txpsql.php

Offline

#6 2013-11-05 12:10:13

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: MySQL database fields definition.

Quoting myself:

Textpattern’s database field definitions are in places wrong; some of which we have resolved in 4.6-dev.

I general there has been improvements to field definitions. Where these integers come down to, is that we can’t simply downgrade field types to lower storage space, as that causes issues if the table contains a value greater than what the new type allows. Albeit changes are small, and no one should be doing it, some plugins do use fields to store values that aren’t used by core.

For instance, I myself use negative statuses to keep of track of purged articles; each purged article uses n*-1 of the original status. Now if we changed the status to unsigned, things would break. For boolean fields the change of course is smaller; its hard to find good reason to use the field to store something else.

Offline

#7 2013-11-05 12:32:08

geralt
Member
From: Al otro lado de la pantalla
Registered: 2008-03-27
Posts: 12
Website

Re: MySQL database fields definition.

Firts of all, thanks for your answers.

I’m agree with you that fixing data types on update.php could be dangerous. But, why not include it on TPX’s installation process?

This action could bring problems in the future with actual plugins that use actual database structure, I know it, but in some moment we should do things well :-)

Offline

Board footer

Powered by FluxBB