Des requêtes à problèmes?

17 septembre 2017

Quand MySQL se me à déraper, c’est habituellement l’oeuvre de quelques requêtes SQL problématiques.  Un petit rappel pour vous aider à trouver la/les coupables!

Publicités

MySQL : quelques lectures

13 avril 2017

Vous cherchez des solutions à des problèmes 1000 fois rencontrés?  Il y a de grandes chances que vous trouviez ce qu’il vous faut ici!

Un excellent blogue consacré à MySQL sur lequel je suis tombé par hasard, lefred.be.

Un article portant sur l’erreur 1215 (« Cannot add foreign key constraint« ).

Les InnoDB Page merge & split expliqués en détail dans ce billet.

Comment choisir l’index approprié pour les requêtes avec égalité ou LIKE ?

Les attaques de réseau et MySQL : une série d’articles sur MySQL et la sécurité.

Configuration de base de MySQL 5.7 : quelques trucs et suggestions.


Les plaques du Congo

28 mars 2017

Comment générer une clef séquentielle et incrémentale composée d’une partie numérique et d’un suffixe lettré?

Comme c’est une situation souvent rencontrée et que les gens détestent habituellement s’attaquer aux procédures stockées et/ou évitent d’utiliser leur langage de programmation favori (pour avoir une solution à 100% en SQL), j’ai pensé vous montrer le problème qu’on m’a demandé de résoudre en SQL et ma solution (qui peut facilement être adaptée aux problèmes similaires)…

Dans le cas qui nous intéresse, il s’agit de plaques d’immatriculation de la République du Congo (format CEMAC).


/*
En supposant la définition suivante

CREATE TABLE plaques(plaque VARCHAR(10));

Et le format de plaque d'immatriculation suivant :

RC-0000-AA
RC-0001-AA
...
RC-9999-AA
RC-0000-AB
RC-0001-AB
...
RC-9999-AZ
RC-0000-BA
...
RC-9999-BZ
RC-0000-CA
RC-0001-CA

Comment générer le prochain numéro 
de plaque d'immatriculation disponible?
*/

SELECT 
    CONCAT(prefixe, 
          '-', 
          LPAD(IF(numero=9999, 0, numero+1), 4, '0'), 
          '-', 
          IF(numero=9999, prochain_suffixe, suffixe)
    ) AS nouvelle_plaque
FROM
(
SELECT 
    MID(plaque, 1, 2) AS prefixe, 
    (MID(plaque, 4, 4) + 0) AS numero, 
    MID(plaque, 9, 2) AS suffixe, 
    IF( MID(plaque, 10, 1)='Z', 
        CONCAT(CHAR(ASCII(MID(plaque, 9, 1)) + 1), 'A'), 
        CONCAT(MID(plaque, 9, 1), CHAR(ASCII(MID(plaque, 10, 1)) + 1))
    ) AS prochain_suffixe
FROM 
    plaques
ORDER BY 
    suffixe DESC, numero DESC
LIMIT 1
) t


The order of indexes

28 février 2017

If you thought all you had to do was to declare a few indexes here and there and MySQL would magically be fast, you’ll be surprised reading this excellent article.


MySQL and UUID

28 septembre 2016

MySQL 8.0.0 has a few new UUID functions!  Read all about this here!


InnoDb variables

9 septembre 2016

Sure, there are tools and script to help you fine tune your MySQL server but there’s nothing like using your brain.

Pythian has done a wonderful job of explaining what all those InnoDb-related variables in a series of articles…

Exposing Innodb Internals via System Variables: Part 1, Memory
Exposing Innodb Internals via System Variables: Part 2, I/O (structure and logs)
Exposing Innodb Internals via System Variables: Part 3, I/O (Table data)
Exposing Innodb Internals via System Variables: Part 4, Concurrency
Exposing Innodb Internals via System Variables: Part 5, Consistency / Statistics handling


Freewill in progress (2)

3 août 2016

Freewill Selection Policies(Click to enlarge)

What’s up?

As you can see, Freewill now supports 17 different selection policies.  At this point, all of them are coded but only half of them have been tested.

The 11 available termination policies are coded, half of them tested.

So far, only 2 mutation policies are available.  Both of them are coded and tested. I will probably need a few extras for TSP type of problems as well as numerically parametrized problems (e.g. De Jong functions with a domain for each variable).  I’ll probably add 3-4 other ones specific to the problem that started all this adventure!

Only one immigration policy (no immigration!) is available and it will stay that way for a long time.  I’ll wait until I am hyper confident that this framework is rock solid before introducing parallelism and exchange of individuals between « islands » (i.e. simulations).  This one is a faaaaaaar away!

Six crossover policies are available as of now .  This area will require some (minor I think at first glance) changes for the TSP type of problems : not quite decided on the approach I will take to solve this.  Since crossover is often very problem/chromosome specific, I’ll probably delay those change until the end, once I have all examples coded and ready to be tested to have a better idea of what is needed.  But I will definitely add a few (3-4) crossover policies tailored for the Ruzzle problem.

I have solved the discrepancy (see here and here) between my results and the TSPLIB ones regarding the tour length of the Burma14 problem.  Will probably add a lot bigger TSP problem to see how the framework can handle an extremely huge search space! Oh!  And I need to clean up all the crap I added/modified while looking for the problem of « distance difference » : 2 classes were butchered in the process!

I need to add a few « crash test dummy » classes to test all those different selection policies (and crossover) in a simpler and more efficient manner!  Or I should kick myself in the %*&#$!@ and code the « bits » example classes…

I will soon work on a customizable display of statistics.  All that’s needed is already there, it’s just a matter of gluing everything together!

Once I’m done with the 8 queens problems, I’ll attack the numerically parametrized problems.  Will probably have 2-3 examples (from De Jong functions) as well as the INSANE Griewank function.

The classes used for randomly choosing the next parent chromosomes as well as scaling/ranking can be optimized.  But since they just work great since day 1, I’ll keep that for the very end.  But I know they can be a lot faster than what they are right now.

I also plan on having a very basic export mechanism so I can dump all those ruzzle chromosomes in a MySQL database to be able to do some reporting and study the various policies and their effects.

I started adding comments to the classes, mostly to keep references, maintain a todo list per class and add some notes for myself to quickly remember why things work that way!

I’ll probably have an image by tomorrow that will run simulations for the ruzzle problem full-time. I wanna beat that record!

 

Save

Save

Save

Save