[MDEV-595] LP:1006160 - View used via a trigger references old columns Created: 2012-05-29 Updated: 2022-09-08 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 10.0.0, 5.5.28, 5.3.10, 5.2.12, 5.1.62 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | nbrnhardt (Inactive) | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | Launchpad | ||
| Attachments: |
|
| Description |
|
MariaDB 5.5.23 on Windows 32 bits tiggers following message in Windows application log: Slave SQL: Query caused different errors on master and slave. Error on master: message (format)='View '%-.192s.%-.192s' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them' error code=1356 ; Error on slave: actual message='no error', error code=0. Default database: 'dbweilandt2'. Query: 'UPDATE vorgangsliste SET gerätestatusid = 4,gerätestatusid=4,garantie=NULL,`timestamp`= NOW() WHERE vorgangsnr = 190655', Error_code: 0 Before that, a column name was changed (which usually triggers a "...references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights..." on views that use the old column name. At the time the above error was triggered, all views with reference to the changed column used the new column name. The only explanation is that somewhere in cache or Aria log file there was still the old name. "Vorgangsliste" is a table that triggers some views on update or on insert, but none of these triggers have references to the changed table. Table format is Aria. The only workaround to get the master working like it should was to stop and restart it. The master has been working for some weeks. Is there any chance to reproduce the problem? |
| Comments |
| Comment by Elena Stepanova [ 2012-05-30 ] |
|
Re: different errors on master and slave. Error on master: message (format)='View '% > "Vorgangsliste" is a table that triggers some views on update or on insert, I'm not quite sure I understand what you mean by this. |
| Comment by nbrnhardt (Inactive) [ 2012-06-11 ] |
|
Re: different errors on master and slave. Error on master: message (format)='View '% I changed a column name in table A and all corresponding VIEWS that use it. The EXPECTED bahavior is that MariaDB should only use the new column name. Nontheless, on the master server it complains about invalid references. Maybe the VIEW was stored in memory/cache with the old column name and did not refresh when it got updated? The error disappeared on the master server when I restarted it. One of the slave uses the same system (Windows 32bit) and configurration file as the master, but here no error occured. I try to reproduce the problem and post it here if I am successful. You would need a couple of tables, JOIN them in a VIEW, create another table with a trigger ON UPDATE that SELECTs the VIEW, and save changes from that view in another tables. Reference is always an ID as PRIMARY KEY. |
| Comment by nbrnhardt (Inactive) [ 2012-06-11 ] |
|
Re: different errors on master and slave. Error on master: message (format)='View '% ======= Table V is updated --> trigger is run ON UPDATE Trigger does (simplified) REPLACE INTO another_database.statistics SELECT * FROM VIEW vw WHERE NEW.id = vw.id VIEW does a SELECT FROM a JOIN b USING(id) JOIN c USING(id) whereas id is the PRIMARY KEY. Column name in table B gets changed, as well as the respective name in VIEW. A select from VIEW is OK, does what it should, but the trigger fails on master server, but not on slave. |
| Comment by nbrnhardt (Inactive) [ 2012-06-11 ] |
|
Re: different errors on master and slave. Error on master: message (format)='View '% Run as SQL: === SQL BEGIN === Now, create the trigger: CREATE TRIGGER `t_v` AFTER UPDATE ON `v` FOR EACH ROW BEGIN And run more SQL: === SQL BEGIN === /* Do some update to start TRIGGER */ /* ALTER COLUMN NAME IN TABLE */ /* ALTER COLUMN NAME IN CORRESPONDING VIEW */ /* Do some update to start TRIGGER again*/ My MariaDB server throws SQL error 1356: View 'test.view' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them While UPDATE `v` SET `Column 2`=15 WHERE `id`=3 LIMIT 1; produces the error, doing a SELECT * FROM view is working fine: /* Affected rows: 0 Found rows: 3 Warnings: 0 Duration for 1 query: 0,016 sec. */ Can you confirm? |
| Comment by Elena Stepanova [ 2012-06-11 ] |
|
Re: different errors on master and slave. Error on master: message (format)='View '% >> Can you confirm? Yes, I can confirm the usage of the old name when SELECT is invoked by a trigger. A shorter test case is below. However, I could not reproduce the replication error. Maybe something that happened on the slave between changing the structures and using the trigger caused flushing tables, explicitly or implicitly. Test case (for old column usage): CREATE TABLE t1 (id INT, oldname VARCHAR(3)); CREATE VIEW v AS SELECT id, oldname FROM t1; CREATE TRIGGER tr AFTER UPDATE ON t2 FOR EACH ROW INSERT INTO t2 VALUES (1),(2),(3); UPDATE t2 SET id=4 WHERE id=3; ALTER TABLE t1 CHANGE COLUMN oldname newname VARCHAR(3); CREATE OR REPLACE VIEW v AS SELECT id, newname FROM t1;
UPDATE t2 SET id=15 WHERE id=4; |
| Comment by Rasmus Johansson (Inactive) [ 2012-06-11 ] |
|
Launchpad bug id: 1006160 |
| Comment by Sergei Golubchik [ 2012-11-19 ] |
|
wil be fixed in 10.0 when we merge WL#4179 "Stored programs: validation of stored program statements" from 5.6 |