DrJohnZoidberg
Honorary Master
I'm back once again in dire need of the MyBB collective mind 
I'm trying to figure out how to best store some information in a MySQL database.
The scenario is that I have a table with customer data like name, email, signup dates, etc. The problem comes in because the web front-end allows admins to also create custom data fields which can differ between users as each user can be part of a separate list. So for one customer list we may have 3 custom data fields for things like date of last purchase, total purchases and country while another list may only has 1 custom field.
TL/DR :: If you already know what I want go to next TL/DR
The way it is currently handled is in the lists table there is a column called custom_fields which handles the custom field header information, like the custom field name and the data type (can be date, text or numeric). This is all stored in the one field and the data is given a delimiter to allow the system to decipher it again, so a typical field will look like this:
So each custom field is delimited by %s% and then each custom fields type is delimited by a colon
.
Then in the customer table there is also a column which matches this delimited format but it contains the actual data for that customer, so it would look like:
This works great as a simple measure but it is very inefficient when you try and search through this data as it first has to be broken up and then calculations must be done on them (currently in php). It works fine for small lists but as soon as you start hitting 100k record it noticeably starts slowing down.
TL/DR Continuation...
My question is how do store these variable custom fields in database tables so I can do MySQL queries instead of having to hack the data to pieces in php?
If the custom fields could only be one data type it wouldn't be a problem, the issue is that there are 3 different data types (well date and numeric could be stored in the same type but not the text) possible and to achieve my blissful goal I need them to be stored as the correct MySQL data types.
Any useful input is appreciated.
I'm trying to figure out how to best store some information in a MySQL database.
The scenario is that I have a table with customer data like name, email, signup dates, etc. The problem comes in because the web front-end allows admins to also create custom data fields which can differ between users as each user can be part of a separate list. So for one customer list we may have 3 custom data fields for things like date of last purchase, total purchases and country while another list may only has 1 custom field.
TL/DR :: If you already know what I want go to next TL/DR
The way it is currently handled is in the lists table there is a column called custom_fields which handles the custom field header information, like the custom field name and the data type (can be date, text or numeric). This is all stored in the one field and the data is given a delimiter to allow the system to decipher it again, so a typical field will look like this:
Code:
Last Purchase:Date%s%Total Purchases:Numeric%s%Country:Text
So each custom field is delimited by %s% and then each custom fields type is delimited by a colon
Code:
(:)
Then in the customer table there is also a column which matches this delimited format but it contains the actual data for that customer, so it would look like:
Code:
1021327200%s%500.42%s%South Africa
This works great as a simple measure but it is very inefficient when you try and search through this data as it first has to be broken up and then calculations must be done on them (currently in php). It works fine for small lists but as soon as you start hitting 100k record it noticeably starts slowing down.
TL/DR Continuation...
My question is how do store these variable custom fields in database tables so I can do MySQL queries instead of having to hack the data to pieces in php?
If the custom fields could only be one data type it wouldn't be a problem, the issue is that there are 3 different data types (well date and numeric could be stored in the same type but not the text) possible and to achieve my blissful goal I need them to be stored as the correct MySQL data types.
Any useful input is appreciated.
Last edited: