Skip to content

[Enhancement]: LONGTEXT attribute type #2470

Open

Description

@objecttothis

New Feature

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.

Activity

  1. self-assigned this
    on Jun 24, 2019
  2. added this to the 3.4.0 milestone on Jun 24, 2019
  3. jekkos commented on Jul 5, 2019

    @jekkos
    Member

    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.

  4. nerv55 commented on Sep 13, 2019

    @nerv55
    Contributor

    @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.

  5. objecttothis commented on Mar 23, 2020

    @objecttothis
    MemberAuthor

    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?

  6. objecttothis commented on May 13, 2020

    @objecttothis
    MemberAuthor

    @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?

  7. changed the title [-]TEXT Attribute length limit[/-] [+]Enchancement: LONGTEXT Attribute type[/+] on May 13, 2020
  8. jekkos commented on May 14, 2020

    @jekkos
    Member

    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.

  9. objecttothis commented on Aug 6, 2020

    @objecttothis
    MemberAuthor

    @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?

  10. objecttothis commented on Aug 6, 2020

    @objecttothis
    MemberAuthor

    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.

  11. objecttothis commented on Aug 6, 2020

    @objecttothis
    MemberAuthor

    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.

  12. jekkos commented on Aug 10, 2020

    @jekkos
    Member

    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?

  13. objecttothis commented on Aug 11, 2020

    @objecttothis
    MemberAuthor

    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.

  14. objecttothis commented on Aug 11, 2020

    @objecttothis
    MemberAuthor

    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?

  15. jekkos commented on Aug 11, 2020

    @jekkos
    Member

    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?

  16. jekkos commented on Aug 11, 2020

    @jekkos
    Member

    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?

  17. jekkos commented on Aug 11, 2020

    @jekkos
    Member

    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)?

  18. jekkos commented on Aug 11, 2020

    @jekkos
    Member

    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.
  19. jekkos commented on Aug 12, 2020

    @jekkos
    Member

    Ok maybe I forgot that we are using pagination on the resultset so that will limit the number of rows fetched.

  20. objecttothis commented on Aug 12, 2020

    @objecttothis
    MemberAuthor

    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.

  21. jekkos commented on Aug 13, 2020

    @jekkos
    Member

    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)?

  22. objecttothis commented on Aug 13, 2020

    @objecttothis
    MemberAuthor

    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.

  23. objecttothis commented on Aug 14, 2020

    @objecttothis
    MemberAuthor

    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.

  24. jekkos commented on Aug 17, 2020

    @jekkos
    Member

    Ok commented on the other isssue.

  25. objecttothis commented on Sep 1, 2020

    @objecttothis
    MemberAuthor

    @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?

  26. modified the milestones: 3.4.0, 3.5.0 on Dec 10, 2022
  27. changed the title [-]Enchancement: LONGTEXT Attribute type[/-] [+][Enhancement]: LONGTEXT attribute type[/+] on Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions