You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently (as of 3.3.0) our TEXT Attribute type is stored in the database (attribute_values) as a VARCHAR(255) which is perfect for most attribute values. There is one category of Attribute in which this length is far too short. Descriptions. In the book industry publisher synopsis, table of contents, forewards, etc would all be far too long to fit here. Outside the book industry, many products have descriptions on the back of the packaging that would also not fit in our current size limitation.
We do currently have a VARCHAR(255) called description and a tinyint(1) called allow_alt_description in the items table but neither solves the problem.
What I'd like to propose is creating an Attribute type called LONGTEXT (or maybe EXTENDEDTEXT) with a column in the attribute_values table setup as a TEXT object. This would give users the ability to create attributes which have length up to 65,536 bytes (~64kb).
To save space we would need set a default NULL constraint and to eliminate performance hit, I don't think these would be searchable by default. Given that OSPOS is a POS and inventory management application, it may not directly benefit OSPOS to have this Attribute Type available, but considering that myself and others will be working with APIs to update their websites to contain these kinds of descriptions, I think there is a need. Plus I'm fine with doing all the work on it.
The question of whether we then remove the description from the items table in favor of making it an attribute can be addressed separately. I, personally, see the description in the items table as a better fit for an attribute because it is an optional element describing the item in a similar way that color, weight and size are.
Out of interest: where would you then plan to view those lengthy descriptions? Imo we currently don't really have a view to show data like that properly.
@objecttothis I agree with you,@jekkos as to where this extended information can be displayed, it can be displayed on the invoices or in the sales reports.
Due to their size, LONGTEXT fields would not appear in the table visibility for items, but perhaps a new visibility selection could be created to add visibility to receipts. Most people will likely be using it as more metadata on the product and some will use it in 3rd party integrations.
In the database, it should be decided what the best type is to store the information and then the infrastructure in the controller and model needs to be implemented. I'm fine with doing the legwork, but need people to weigh in on the structure and details. @jekkos@daN4cat, thoughts?
@opensourcepos/org I am beginning to look at this now since we need the data even more with the RESTful API interface to send the data to our eCommerce site.
I'd like to add a column to attribute_values with a type of TEXT. and then build the framework within attributes to have a LONGTEXT attribute type which will utilize this format. There should not be a performance hit against the app since we are not doing a SELECT * against that table, but instead that table is accessed through specific JOIN operations with the attribute_links table.
As I said before, I will setup the view in views/items/form.php to display this as a textarea form which will be designed by default to not take up more than 4-5 lines of text. If I'm feeling squirrelly enough I'll make it so that the textarea is expandable and show characters typed/Maximum. (eg. 123/65535)
Regarding performance, indeed you can use attributes but still have them disabled in your table view, so it's completely up to the user if he wants to query that table or not.
This sounds like a good adddition to me, I guess you kind of know how it works by now, you'll have to change the partial view to include a textarea in case this type of attribute is present.
@jekkos I'm working on this issue now. Right now the attribute_value column in the ospos_attribute_values table is VARCHAR(255). What if we were to just change that field to VARCHAR(10000) instead of adding another column called attribute_longvalue (or something similar)? That eliminates the need for a separate column without additional overhead since VARCHAR is dynamically allocated and the index shouldn't be affected because indexes are limited to 768 bytes. The same would be true with the description column in the ospos_items table. Thoughts?
If we still want to distinguish between a TEXT attribute type and LONGTEXT we could by creating the attribute type but storing it the same in the database (with VARCHAR(10000)) and just truncating the value at 255 if the attribute type is TEXT when we save the value in the model. Honestly, I think we should just increase the VARCHAR max length in the database and not add a LONGTEXT attribute type but just let TEXT be up to 10000 characters.
After further review, I think we should create the LONGTEXT attribute type but store it in the database in the attribute_value column and lengthen the structure from VARCHAR(255) to VARCHAR(10000). This would involve modifying the unique index on the column to a prefixed index. The prefix length that would likely be the most effective would probably by 100 but if we want to guarantee compatibility we could go with a prefix length of 255.
The reason I think we ought to still create the type is so that we can represent the attribute in the item form as a textarea not dis-similar to the way we have description setup. This is a more conducive form type for longer text strings like this.
I'm not sure what is best for this one. Ideally we should not have this extended field if it's not used, but I guess that will make things very complicated now.
I guess for the modelling it's probably easy to reuse the existing value field and extend it? But how do you then decide when you want to show it as a textarea? Based on the definition type?
I'm not sure what is best for this one. Ideally we should not have this extended field if it's not used, but I guess that will make things very complicated now.
I guess for the modelling it's probably easy to reuse the existing value field and extend it? But how do you then decide when you want to show it as a textarea? Based on the definition type?
It probably needs to be modeled after DROPDOWN and CHECKBOX in that both of those also re-use the attribute_value field in the attribute_values table but have their own business logic to determine how they get displayed and manipulated in the application. This would take it a step further and make the attribute_value column a VARCHAR(10000) and replace the index on that column with a prefix index of 255 characters. That size of an index replicates the index we have now and guarantees compatibility in the migration, but most users would benefit more from a prefix index of 50 or 100 instead.
I'm about half-way through the coding of the LONGTEXT attribute type and I've discovered that another difference is that, like items.description, this attribute type needs to have an unchangeable default visibility flag of 0. This is because you don't want a crazy long text mucking up your items table view.
We also need to decide if we want to restrict TEXT attribute types to 255 or not. The current behavior is that when a TEXT attribute type is longer that 255 the application saves the value but the database truncates the value with no warning or error. Once I change the column to varchar(10000), the field won't truncate text values longer than 255. We could approach is one of three ways:
1 Do nothing and allow TEXT attributes to be longer than 255.
2 Replicate current behavior by truncating the TEXT value at 255 before sending it to the database and sending no message to the user.
3 Replicate current behavior with a warning dialog to the user that the value will be truncated (think delete warning dialog box in Receivings).
Another advantage of not adding a new column is that the amount of code you need to change is probably
I'm not sure what is best for this one. Ideally we should not have this extended field if it's not used, but I guess that will make things very complicated now.
I guess for the modelling it's probably easy to reuse the existing value field and extend it? But how do you then decide when you want to show it as a textarea? Based on the definition type?
It probably needs to be modeled after DROPDOWN and CHECKBOX in that both of those also re-use the attribute_value field in the attribute_values table but have their own business logic to determine how they get displayed and manipulated in the application. This would take it a step further and make the attribute_value column a VARCHAR(10000) and replace the index on that column with a prefix index of 255 characters. That size of an index replicates the index we have now and guarantees compatibility in the migration, but most users would benefit more from a prefix index of 50 or 100 instead.
I'm about half-way through the coding of the LONGTEXT attribute type and I've discovered that another difference is that, like items.description, this attribute type needs to have an unchangeable default visibility flag of 0. This is because you don't want a crazy long text mucking up your items table view.
I guess that should not be an issue as long as you don't use it to store more than just a description?
We also need to decide if we want to restrict TEXT attribute types to 255 or not. The current behavior is that when a TEXT attribute type is longer that 255 the application saves the value but the database truncates the value with no warning or error. Once I change the column to varchar(10000), the field won't truncate text values longer than 255. We could approach is one of three ways:
1 Do nothing and allow TEXT attributes to be longer than 255.
2 Replicate current behavior by truncating the TEXT value at 255 before sending it to the database and sending no message to the user.
3 Replicate current behavior with a warning dialog to the user that the value will be truncated (think delete warning dialog box in Receivings).
Thoughts?
It's probably better not to truncate it at all then. I'm not sure on the explanation on the prefix index. Does it mean that you won't have a full text search on the field? I mean if you search for a value, do you want this whole field to be scanned or will it be the first x characters only?
A last option is one that would probably be more space efficient would be to save the long text in a separate table. So that means further denormalization.
A downside is that it wil complicate the search queries and make those more complex (an extra join in this case). But it depends on whether you want full text search then or not, as it could make sense to only do that extra join in the `get_info´ (so when showing specific detailqs)?
I might have some concerns on the final outcome (performance hit) if we go for extending the value field and query when viewing the items table
Denormalize table structure further by adding a table with attribute_id, longtext that is only queried when retrieving details?
Fulltext search or not ? Not sure if this is even feasible performancewise.
If not we can keep the overview fast and simple (as it is now)
Or we extend the current column to more characters, but then a resultset might become huge depending on how much text you store with every item? Say you have 10k+ items with a shitload of text for a couple of thousand rows... I'm not certain whether this will scale well.
Prefix indexes and indexes are limited to 768 bytes and 767 bytes respectively.
Adding a FULLTEXT index will allow full text searches.
It definitely would guarantee that attribute_links not get cluttered. Perhaps the best way to handle this would be to still use attribute_links as our link table. Since attribute_id is not required to be unique, in the business logic we just check the definition type. if it's LONGTEXT then rather than getting the value from attribute_values, we get the value from attribute_longvalues. Saving would be the same idea.
The only downside is that this creates more work in the business logic.
With the pagination, that you mentioned, I honestly don't think there would be a huge performance hit with loading pages (remember, LONGTEXT isn't displayed in the items table view. Only in the Item form).
The question is whether search within attributes would take a performance hit. I imagine that as long as there is a FULLTEXT index and a prefix index then there wouldn't be a performance hit. If search attributes is checked we may have to also have the user choose that they want a fulltext search and then specify a fulltext search in that case (https://dev.mysql.com/doc/refman/8.0/en/fulltext-search.html). Otherwise it would use the prefix index for its searching.
Prefix indexes and indexes are limited to 768 bytes and 767 bytes respectively.
Adding a FULLTEXT index will allow full text searches.
Ok I ddin't know Mysql had this thpe of index, but I guess in that case it should be fine (as it's made for that purpose)?
Prefix indexes and indexes are limited to 768 bytes and 767 bytes respectively.
Adding a FULLTEXT index will allow full text searches.
Ok I ddin't know Mysql had this thpe of index, but I guess in that case it should be fine (as it's made for that purpose)?
I have a pretty substantial attribute_links table (202k rows) and attribute_values table (42.5k rows). I'll probably add 1k rows to the values table with Forewords and chapter samples from books then performance test it. I have a fairly low tolerance of slowdown of the database because of this third party integration that packs the data into JSON and sends it to a 3rd party API. Even 0.1 second per item increase in that and it would be too much for my tastes. Item imports is another place that this can be really affected. Doing an update import with 1000 rows is a great place to test performance hits. If it turns out to be not efficient, then I will rework that part of the logic to use a separate attribute_longvalues table to handle LONGTEXT attributes.
In my first tests I'm seeing that Full text search still works fine with only a prefix index of 255 bytes. I think this is because the MySQL engine isn't using the index during a full text search. I'll test the performance later. I have run into a bit of a bug in that currently the "search attributes" option in the items table view only searches attributes that have an items visibility flag set in the definition. I'll create a separate issue to address this.
@jekkos I've run into a problem with the UNIQUE constraint. Perhaps there is a better solution for this, but I'm not sure.
Problem: If I change attribute_values to a VARCHAR(10000) and add a prefix unique index then any row that gets added with the same first 255 characters but different characters after that will fail to insert because there would be a duplicate entry in the prefix index.
The only way I've found to do this in my searches online, would be to remove the index from attribute_value, create a hash column and store a SHA1 hash of the attribute_value and add a unique index on the hash column. I think doing this would create a lot of extra business logic in storing and retrieving attribute_values. Ideas?
Activity
jekkos commentedon Jul 5, 2019
Out of interest: where would you then plan to view those lengthy descriptions? Imo we currently don't really have a view to show data like that properly.
nerv55 commentedon Sep 13, 2019
@objecttothis I agree with you,@jekkos as to where this extended information can be displayed, it can be displayed on the invoices or in the sales reports.
objecttothis commentedon Mar 23, 2020
In the item view, these attributes would be represented using the TEXTAREA input type which would allow newline by pressing enter. Normally the enter key submits the form, but if the active input field is a TEXTAREA then it creates a new line. We could potentially use jQuery to expand the field on focus (https://stackoverflow.com/questions/6379745/onclick-expand-textbox-width/21977908) and then return the field to its normal size on blur.
Due to their size, LONGTEXT fields would not appear in the table visibility for items, but perhaps a new visibility selection could be created to add visibility to receipts. Most people will likely be using it as more metadata on the product and some will use it in 3rd party integrations.
In the database, it should be decided what the best type is to store the information and then the infrastructure in the controller and model needs to be implemented. I'm fine with doing the legwork, but need people to weigh in on the structure and details. @jekkos @daN4cat, thoughts?
objecttothis commentedon May 13, 2020
@opensourcepos/org I am beginning to look at this now since we need the data even more with the RESTful API interface to send the data to our eCommerce site.
I'd like to add a column to attribute_values with a type of TEXT. and then build the framework within attributes to have a LONGTEXT attribute type which will utilize this format. There should not be a performance hit against the app since we are not doing a SELECT * against that table, but instead that table is accessed through specific JOIN operations with the attribute_links table.
As I said before, I will setup the view in views/items/form.php to display this as a textarea form which will be designed by default to not take up more than 4-5 lines of text. If I'm feeling squirrelly enough I'll make it so that the textarea is expandable and show characters typed/Maximum. (eg. 123/65535)
Does anyone have objections to this approach?
[-]TEXT Attribute length limit[/-][+]Enchancement: LONGTEXT Attribute type[/+]jekkos commentedon May 14, 2020
Regarding performance, indeed you can use attributes but still have them disabled in your table view, so it's completely up to the user if he wants to query that table or not.
This sounds like a good adddition to me, I guess you kind of know how it works by now, you'll have to change the partial view to include a textarea in case this type of attribute is present.
objecttothis commentedon Aug 6, 2020
@jekkos I'm working on this issue now. Right now the attribute_value column in the ospos_attribute_values table is VARCHAR(255). What if we were to just change that field to VARCHAR(10000) instead of adding another column called attribute_longvalue (or something similar)? That eliminates the need for a separate column without additional overhead since VARCHAR is dynamically allocated and the index shouldn't be affected because indexes are limited to 768 bytes. The same would be true with the description column in the ospos_items table. Thoughts?
objecttothis commentedon Aug 6, 2020
If we still want to distinguish between a TEXT attribute type and LONGTEXT we could by creating the attribute type but storing it the same in the database (with VARCHAR(10000)) and just truncating the value at 255 if the attribute type is TEXT when we save the value in the model. Honestly, I think we should just increase the VARCHAR max length in the database and not add a LONGTEXT attribute type but just let TEXT be up to 10000 characters.
objecttothis commentedon Aug 6, 2020
After further review, I think we should create the LONGTEXT attribute type but store it in the database in the attribute_value column and lengthen the structure from VARCHAR(255) to VARCHAR(10000). This would involve modifying the unique index on the column to a prefixed index. The prefix length that would likely be the most effective would probably by 100 but if we want to guarantee compatibility we could go with a prefix length of 255.
The reason I think we ought to still create the type is so that we can represent the attribute in the item form as a textarea not dis-similar to the way we have description setup. This is a more conducive form type for longer text strings like this.
jekkos commentedon Aug 10, 2020
I'm not sure what is best for this one. Ideally we should not have this extended field if it's not used, but I guess that will make things very complicated now.
I guess for the modelling it's probably easy to reuse the existing value field and extend it? But how do you then decide when you want to show it as a textarea? Based on the definition type?
objecttothis commentedon Aug 11, 2020
It probably needs to be modeled after DROPDOWN and CHECKBOX in that both of those also re-use the attribute_value field in the attribute_values table but have their own business logic to determine how they get displayed and manipulated in the application. This would take it a step further and make the attribute_value column a VARCHAR(10000) and replace the index on that column with a prefix index of 255 characters. That size of an index replicates the index we have now and guarantees compatibility in the migration, but most users would benefit more from a prefix index of 50 or 100 instead.
I'm about half-way through the coding of the LONGTEXT attribute type and I've discovered that another difference is that, like items.description, this attribute type needs to have an unchangeable default visibility flag of 0. This is because you don't want a crazy long text mucking up your items table view.
objecttothis commentedon Aug 11, 2020
We also need to decide if we want to restrict TEXT attribute types to 255 or not. The current behavior is that when a TEXT attribute type is longer that 255 the application saves the value but the database truncates the value with no warning or error. Once I change the column to varchar(10000), the field won't truncate text values longer than 255. We could approach is one of three ways:
1 Do nothing and allow TEXT attributes to be longer than 255.
2 Replicate current behavior by truncating the TEXT value at 255 before sending it to the database and sending no message to the user.
3 Replicate current behavior with a warning dialog to the user that the value will be truncated (think delete warning dialog box in Receivings).
Thoughts?
jekkos commentedon Aug 11, 2020
Another advantage of not adding a new column is that the amount of code you need to change is probably
I guess that should not be an issue as long as you don't use it to store more than just a description?
jekkos commentedon Aug 11, 2020
It's probably better not to truncate it at all then. I'm not sure on the explanation on the prefix index. Does it mean that you won't have a full text search on the field? I mean if you search for a value, do you want this whole field to be scanned or will it be the first x characters only?
jekkos commentedon Aug 11, 2020
A last option is one that would probably be more space efficient would be to save the long text in a separate table. So that means further denormalization.
A downside is that it wil complicate the search queries and make those more complex (an extra join in this case). But it depends on whether you want full text search then or not, as it could make sense to only do that extra join in the `get_info´ (so when showing specific detailqs)?
jekkos commentedon Aug 11, 2020
I might have some concerns on the final outcome (performance hit) if we go for extending the value field and query when viewing the items table
jekkos commentedon Aug 12, 2020
Ok maybe I forgot that we are using pagination on the resultset so that will limit the number of rows fetched.
objecttothis commentedon Aug 12, 2020
https://dev.mysql.com/doc/refman/5.7/en/column-indexes.html#column-indexes-prefix
Prefix indexes and indexes are limited to 768 bytes and 767 bytes respectively.
Adding a FULLTEXT index will allow full text searches.
It definitely would guarantee that attribute_links not get cluttered. Perhaps the best way to handle this would be to still use attribute_links as our link table. Since attribute_id is not required to be unique, in the business logic we just check the definition type. if it's LONGTEXT then rather than getting the value from attribute_values, we get the value from attribute_longvalues. Saving would be the same idea.
The only downside is that this creates more work in the business logic.
With the pagination, that you mentioned, I honestly don't think there would be a huge performance hit with loading pages (remember, LONGTEXT isn't displayed in the items table view. Only in the Item form).
The question is whether search within attributes would take a performance hit. I imagine that as long as there is a FULLTEXT index and a prefix index then there wouldn't be a performance hit. If search attributes is checked we may have to also have the user choose that they want a fulltext search and then specify a fulltext search in that case (https://dev.mysql.com/doc/refman/8.0/en/fulltext-search.html). Otherwise it would use the prefix index for its searching.
jekkos commentedon Aug 13, 2020
objecttothis commentedon Aug 13, 2020
I have a pretty substantial attribute_links table (202k rows) and attribute_values table (42.5k rows). I'll probably add 1k rows to the values table with Forewords and chapter samples from books then performance test it. I have a fairly low tolerance of slowdown of the database because of this third party integration that packs the data into JSON and sends it to a 3rd party API. Even 0.1 second per item increase in that and it would be too much for my tastes. Item imports is another place that this can be really affected. Doing an update import with 1000 rows is a great place to test performance hits. If it turns out to be not efficient, then I will rework that part of the logic to use a separate attribute_longvalues table to handle LONGTEXT attributes.
objecttothis commentedon Aug 14, 2020
In my first tests I'm seeing that Full text search still works fine with only a prefix index of 255 bytes. I think this is because the MySQL engine isn't using the index during a full text search. I'll test the performance later. I have run into a bit of a bug in that currently the "search attributes" option in the items table view only searches attributes that have an items visibility flag set in the definition. I'll create a separate issue to address this.
jekkos commentedon Aug 17, 2020
Ok commented on the other isssue.
objecttothis commentedon Sep 1, 2020
@jekkos I've run into a problem with the UNIQUE constraint. Perhaps there is a better solution for this, but I'm not sure.
Problem: If I change attribute_values to a VARCHAR(10000) and add a prefix unique index then any row that gets added with the same first 255 characters but different characters after that will fail to insert because there would be a duplicate entry in the prefix index.
The only way I've found to do this in my searches online, would be to remove the index from attribute_value, create a hash column and store a SHA1 hash of the attribute_value and add a unique index on the hash column. I think doing this would create a lot of extra business logic in storing and retrieving attribute_values. Ideas?
[-]Enchancement: LONGTEXT Attribute type[/-][+][Enhancement]: LONGTEXT attribute type[/+]