[wp-trac] [WordPress Trac] #63893: wp_usermeta – Unique Key (user_id+meta_key) - efficiency goal

WordPress Trac noreply at wordpress.org
Fri Aug 29 01:37:19 UTC 2025


#63893: wp_usermeta – Unique Key (user_id+meta_key) - efficiency goal
------------------------------+--------------------------------------------
 Reporter:  curtisfraser      |       Owner:  (none)
     Type:  enhancement       |      Status:  new
 Priority:  normal            |   Milestone:  Awaiting Review
Component:  Users             |     Version:  6.8.2
 Severity:  normal            |  Resolution:
 Keywords:  close 2nd-        |     Focuses:  performance, coding-standards
  opinion                     |
------------------------------+--------------------------------------------
Changes (by siliconforks):

 * keywords:   => close 2nd-opinion


Comment:

 Replying to [ticket:63893 curtisfraser]:
 > Just curious as to why there is not a unique key for the wp_usermeta
 table using User_id and Meta_key?
 >
 > At least within any website I have supported, there is no reason to have
 duplicate meta_key records for a User. Is there a reason it is not a
 unique key and indexed on this?

 Having multiple rows with the same `user_id` and `meta_key` is something
 which is supported by the metadata APIs:

 https://developer.wordpress.org/reference/functions/add_user_meta/
 https://developer.wordpress.org/reference/functions/get_user_meta/

 In my experience, this feature is not something which is used very often,
 but there are a few plugins that do make use of this.  (An example:
 [https://wordpress.org/plugins/woo-photo-reviews/ Photo Reviews for
 WooCommerce].)

 > So three requests:
 > - reduce size of meta_key to 150 characters
 > - create unique key using user_id+meta_key
 > - create index on unique key

 That might work fine on your site as long as you're not using any plugins
 that use this feature, but this is not something that is going to work
 everywhere.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63893#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list