sql - MySQL if where not found then insert -


as appear classic "on duplicate key update" question - not.

i have table meta values goes like:

meta_id   |   user_id   |   meta_type   |   meta_value 

thing there can more entries same user_id&&meta_type must not repeat entries same user_id&&meta_type&&meta_value. add unique index these, afraid of 1 thing - meta_value longtext contain larger data.
so when want create unique key (so use on duplicate key update), error:

#1170 - blob/text column 'meta_hodnota' used in key specification without key length

and when tried add limit popped out:

#1071 - specified key long; max key length 767 bytes 

that low possible entry. question how key work:

  1. it saying how long part of column mysql check duplicity , not modify posibility of having max. column value size (max(longtext))
    note: care tripple duplicity smaller entries, dont care duplicity big entries (not in place)
  2. it cutting possibility of having max. column value size(max(longtext)) , leaving 767bytes maximum value of column though column longtext. - not acceptable => here query neccessary? or there way? (e.g.sql-side search , variable save => chosing action according result)

any help/tips on this?

any chance 3072 bytes enough? can use innodb_large_prefix parameter in mysql configuration in case.

if 3072 bytes not enough adding fixed lenght column (something varchar(256)) , use 1 create index. when inserting/updating record can use substr() trim long text 256 char , populate column value.

this of course works if care smaller entries in meta_* said. depending on number of rows disc usage increase little shouldn't issue in cases.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -