[MDEV-14459] ORDER BY on "GENERATED ALWAYS" virtual column is ignored Created: 2017-11-21  Updated: 2017-12-31  Resolved: 2017-12-31

Status: Closed
Project: MariaDB Server
Component/s: Virtual Columns
Affects Version/s: 10.2.10
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Craig Edwards Assignee: Unassigned
Resolution: Incomplete Votes: 0
Labels: need_feedback
Environment:

Linux dedi2.comech.co.uk 3.10.0-327.18.2.el7.x86_64 #1 SMP Thu May 12 11:03:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux



 Description   

I have created a users table, which contains a "generated always" virtual column called "full_name". This virtual column is calculated from two varchar fields, first_name and last_name using CONCAT.

CREATE TABLE `users` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 `username` varchar(50) NOT NULL COMMENT 'User Name',
 `active` tinyint(1) unsigned NOT NULL DEFAULT 1 COMMENT 'Set if the user account is active and allows logins',
 `email` varchar(255) NOT NULL COMMENT 'User email address',
 `first_name` varchar(255) NOT NULL COMMENT 'User First Name',
 `last_name` varchar(255) NOT NULL COMMENT 'User Last Name',
 `full_name` varchar(255) GENERATED ALWAYS AS (concat(`first_name`,' ',`last_name`)) VIRTUAL COMMENT 'Calculated full name field',
 `phone` varchar(150) DEFAULT NULL COMMENT 'User''s phone number',
 `email_confirmed` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'True if the email address provided has been validated',
 `email_confirmation_hash` varchar(64) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL COMMENT 'Verification hash for validating email addresses',
 `pwhash` varchar(128) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL COMMENT 'Password Hash',
 `password_reset_pwhash` varchar(128) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL COMMENT 'New hash to reset password to, if the user confirms the reset via email',
 `password_last_changed` date DEFAULT NULL COMMENT 'Date of last password change',
 `permissions` longtext DEFAULT NULL COMMENT 'User permissions',
 `company_id` bigint(20) unsigned NOT NULL COMMENT 'Company ID FK',
 `reminders` tinyint(1) unsigned NOT NULL DEFAULT 1 COMMENT 'True if the user receives email reminders',
 `data` longtext DEFAULT NULL COMMENT 'Metadata',
 PRIMARY KEY (`id`),
 UNIQUE KEY `unique_usernames` (`username`),
 KEY `company_id_idx` (`company_id`),
 KEY `username_idx` (`username`),
 KEY `reminders` (`reminders`),
 KEY `password_last_changed` (`password_last_changed`),
 KEY `pwhash` (`pwhash`),
 KEY `password_reset_pwhash` (`password_reset_pwhash`),
 KEY `email_confirmed` (`email_confirmed`),
 KEY `email_confirmation_hash` (`email_confirmation_hash`),
 KEY `email` (`email`),
 KEY `active` (`active`),
 KEY `first_name` (`first_name`),
 KEY `last_name` (`last_name`),
 KEY `phone` (`phone`),
 KEY `first_name_last_name` (`first_name`,`last_name`) USING BTREE,
 KEY `full_name` (`full_name`),
 CONSTRAINT `users_companies` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`),
 CONSTRAINT `data` CHECK (`data` is null or json_valid(`data`)),
 CONSTRAINT `permissions_json` CHECK (`permissions` is null or json_valid(`permissions`))
) ENGINE=InnoDB AUTO_INCREMENT=1024 DEFAULT CHARSET=utf8mb4 COMMENT='Username List'

When i try and do an ORDER BY on the full_name column, either ascending or descending, the ORDER BY is silently ignored. This occurs in my own code and also in phpMyAdmin 4.7.3 under PHP 5.6.30.



 Comments   
Comment by Elena Stepanova [ 2017-12-02 ]

Please connect to the server with the command-line client (mysql) and run the query from there. If it still returns the result in a wrong order, please paste the output. You can obfuscate the result any way you want, as long as it's clearly seen that the order is wrong; and also attach the cnf file(s).

Comment by Elena Stepanova [ 2017-12-31 ]

If you have further information on the issue, please comment and the report will be re-opened.

Generated at Thu Feb 08 08:13:43 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.