⌘BABAKOV.NET Let's code!
100% [dark] [ru]

Important Note on Procedure Naming in MySQL!

From the archive
I will tell you about one small nuance that will help save time and nerves. This feature was noticed by me only in MySQL (manifested both in 5 and currently in the test 6th). It is about the need for a special naming of procedures for proper recovery of the database from the MySQL archive (dump).

The meaning lies in alphabetical order of functions. When creating a dump of the database, all elements are saved in alphabetical order, that is, if in the procedure proc1 call the procedure proc2 — then when recovering from the dump an error will occur because the first to be restored will be the procedure proc1 — which requires proc2 — but it will not be in the database at the time of its recreation.

The way to combat this is the simplest and most effective, is to simply take the rule, never call functions whose names are closer to the beginning of the alphabet than the one from which the function is called.

Personally, I usually try to name functions related to each other the same and number them.

Example:

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_export1` AS 
  select 
    `market_smartdocspec`.`ID_DOCHEAD` AS `ID_DOCHEAD`,
    `market_cards`.`ID_CLASSIF` AS `ID_CLASSIF`,
    `market_smartdocspec`.`ARTICUL` AS `ARTICUL`,
    `market_smartdocspec`.`NAME` AS `NAME`,
    sum(`market_smartdocspec`.`QUANTITY`) AS `QUANTITY`,
    (sum((`market_smartdocspec`.`PRICE` * `market_smartdocspec`.`QUANTITY`)) / sum(`market_smartdocspec`.`QUANTITY`)) AS `PRICE`,
    sum((`market_smartdocspec`.`PRICE` * `market_smartdocspec`.`QUANTITY`)) AS `SUMMA` 
  from 
    (`market_smartdocspec` join `market_cards`) 
  where 
    (`market_smartdocspec`.`ARTICUL` = `market_cards`.`ARTICUL`) 
  group by 
    `market_smartdocspec`.`ID_DOCHEAD`,`market_smartdocspec`.`ARTICUL`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_export2` AS 
  select 
    `view_export1`.`ID_DOCHEAD` AS `ID_DOCHEAD`,
    `view_export1`.`ID_CLASSIF` AS `ID_CLASSIF`,
    `market_classif`.`NAME` AS `NAME_CLASSIF`,
    `view_export1`.`ARTICUL` AS `ARTICUL`,
    `view_export1`.`NAME` AS `NAME`,
    `view_export1`.`QUANTITY` AS `QUANTITY`,
    `market_ostatok`.`QUANTITY` AS `OSTATOK`,
    `view_export1`.`PRICE` AS `PRICE`,
    `market_cards`.`PRICE_SELECT` AS `PRICE1`,
    `view_export1`.`SUMMA` AS `SUMMA`,
    (`market_ostatok`.`QUANTITY` * `market_cards`.`PRICE_SELECT`) AS `SUMMA1` 
  from 
    (((`view_export1` join `market_cards`) join `market_classif`) join `market_ostatok`) 
  where 
    ((`view_export1`.`ARTICUL` = `market_cards`.`ARTICUL`) and (`view_export1`.`ID_CLASSIF` = `market_classif`.`ID`) and (`market_cards`.`ARTICUL` = `market_ostatok`.`IDENT_CARD`)) 
  group by 
    `view_export1`.`ID_DOCHEAD`,`view_export1`.`ARTICUL`;



These views (VIEW) — will be recovered correctly, but if I change the name view_export1 to z_export1 — then an error will occur when recovering.

Comments (0)

No comments yet.

Leave a comment
Comment
Images (up to 5 MB)
Your comment will appear after moderation.