One TRIGGER Fact, Optimizer Rewriting Stuff

  • One thing about TRIGGERs is that you can have 6 triggers per table:

    BEFORE
    AFTER
        INSERT
    UPDATE
    DELETE

    That was brought up at the User Group meeting.

    In other news, I have been reading the MySQL Internals Manual. The most interesting chapter yet is Chapter 3, the optimizer. This can be read out of order, and actually contains lots of information that folks can use. For instance:

    WHERE col1=col2 AND col2='x'
    transforms to
    WHERE col1='x' AND col2='x'

    because constant matching is faster.

    Tautologies and always-false statements are usually optimized out of the query so that something like WHERE 0=0 does not waste time by actually being tested.

    A table with 0 or 1 rows is a constant value. Another constant table scenario is WHERE col1=[constant] for all the columns of any UNIQUE or PRIMARY KEYS, assuming they are defined as NOT NULL. This is a good reason to use NOT NULL for column definitions unless you really need NULL.

    A constant table is what is used by the optimizer when you see "const" as the "join type" in the result of an EXPLAIN.

    WHERE col1 in (1,2,3) is the exact same expression as WHERE col1=1 OR col1=2 OR col1=3

    WHERE col1 BETWEEN 1 AND 3 is the exact same expression as WHERE col1>=1 AND col1< =3

    The latter 2 examples are good to know, because the first of the two statements in each case are more clear.

  • I am thanks to this because

    I am thanks to this because we have cleared out some doubts and clarifications. nice features.

    Try: select * from table1

    Try:

    select * from table1 where primaryKey IN (select primaryKey from table2)

    Assuming table2 has more than 1 row, the query will not use the primary key index for table1. Replace the subselect with the actual ids 1,2,3,etc and it will.

    There is a difference in how the optimizer views certain clauses.

    [...] A bit ago ago I posted

    [...] A bit ago ago I posted some optimizer hints and recommended using them to write more readable queries. Today I stumbled across an example of my own work that I changed. This is not quite a case of using BETWEEN instead of AND statements, but it sort of is. Basically, I needed to reuse this query: [...]

    There are some nice features

    There are some nice features about triggers that I think are missing and I'd like to see as future features.

    You an read more at MySQL Trigger Features - http://blog.arabx.com.au/?p=337

    Scott -- The section of the

    Scott -- The section of the manual you're looking at compares =, , , etc.

    For instance, if you give the optimizer

    WHERE expr=1 OR expr=2

    that uses equality. If you give the optimizer

    WHERE expr IN (1,2)

    what does it use? Well, obviously to us, equality. What it says is that if you use constants instead of functions, etc. then it will go faster. It's intuitive that quality comparisons (like expr=1) go faster.

    What the internals manual states is that it doesn't matter how you write it, because they will be processed the same way. If you have a constant in the IN statement, or a constant in each part of the OR, it's faster, no matter what. But there's no difference to the optimizer between using IN() or a bunch of OR statements.

    I find using IN() to be more readable than a bunch of OR statements.

    The manual also says about

    The manual also says about IN ():

    "If all values are constants, they are evaluated according to the type of expr and sorted. The search for the item then is done using a binary search. This means IN is very quick if the IN value list consists entirely of constants."
    (http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html)

    I would have thought that meant there is a considerable difference between IN () and =OR=. Does it not?

    Take Albuterol Inhaler
    Order Inhaler Albuterol
    Buy Albuterol Online no Prescription
    Online Buy Albuterol Without a Prescription
    Purchase Online Without a Prescription Albuterol
    Online Buying Aldactone
    Purchase Online Without a Prescription Aldactone
    Aldactone for Acne
    Buying Aldactone Legally
    Buy Tablets Aldactone Online
    Cheapest Buy Allopurinol
    Purchase Allopurinol Online no Prescription
    Buy Without a Prescription Allopurinol
    Buy Allopurinol Free Delivery
    Legally Order Allopurinol
    Buy Anafranil Without a Prescription
    Buy Anafranil Pills
    Buy Anafranil Medication
    Buying Without a Prescription Anafranil Online
    Take no Prescription Anafranil
    Buying Atarax Overnight Delivery
    Purchase Atarax Free Delivery
    Alternative Purchase Atarax
    Purchase Atarax by Phone
    Legally Purchase Atarax
    Order Avodart Without a Prescription
    Tablets Order Avodart
    Pills Buying Avodart
    Buy Avodart Medication
    Tablets Purchase Avodart
    Alternative Purchase Bactrim
    Take Bactrim Next Day Delivery
    Online Buying Bactrim
    Cheapest Buy Bactrim
    Purchase Bactrim Without a Prescription
    Buy Celecoxib Overnight Delivery
    Purchase Cheapest Celecoxib
    Tablets Buy Celecoxib
    Buying Without Prescription Celecoxib
    Order Online Without a Prescription Celecoxib
    Take Cipro Legally
    Purchase Cipro by Phone
    Purchase Online no Prescription Cipro
    Buy Pills Cipro
    Order Cipro COD
    Purchase Clomid Serophene Generic
    100 Clomid Serophene
    Cheapest Buy Clomid Serophene
    Order Clomid Serophene by Phone
    Take Clomid Serophene Medication
    Buying Dapsone
    Purchase Dapsone COD
    Buy Dapsone Free Delivery
    Take Dapsone Next Day Delivery
    Order Cheapest Dapsone
    Generic Buying Desyrel
    Order Cheap Desyrel
    Take Desyrel Next Day Delivery
    Buy Desyrel Tablets
    Buy Desyrel Cheapest
    Buy Diflucan Medication
    Buy Diflucan Pills
    Take Diflucan Pills
    Purchase no Prescription Diflucan
    Order Cheapest Diflucan
    Buying Dilantin Next Day Delivery
    Dilantin Phenytoin
    Buying Dilantin Overnight Delivery
    Legally Purchase Dilantin
    Purchase Dilantin Alternative
    Purchase Diovan Pills
    Buy Diovan Pills
    Order no Prescription Diovan
    Purchase Online Without Prescription Diovan
    Buy Cheap Diovan
    Buy Doxycycline Medication
    Order Doxycycline Without a Prescription
    Take Doxycycline Daily Dose
    100 Doxycycline
    Buying Doxycycline
    Buy Elavil COD
    Buy Elavil Medication
    Order Elavil Generic
    Order Elavil Pills
    Purchase Elavil Drug
    Order Generic Erythromycin
    Buy Erythromycin Medication
    Buy Erythromycin Without a Prescription
    Purchase Online Without a Prescription Erythromycin
    Buying Erythromycin Overnight Delivery
    Order no Prescription Estrace
    Buying Without Prescription Estrace
    Take Estrace Drug
    Purchase Estrace Alternative
    Order Generic Estrace
    Order Furosemide Pills
    Buy Alternative Furosemide
    Order Pills Furosemide
    Take Furosemide Medication
    Order Cheapest Furosemide
    Buy Glucophage Pills
    Tablets Order Glucophage
    Take Glucophage Legally
    Purchase no Prescription Glucophage
    Why Take Glucophage
    Purchase Imitrex Free Delivery
    Buying Imitrex Without Prescription
    Buying Without a Prescription Imitrex Online
    Buy Cheapest Imitrex
    Imitrex Generic
    Buying Pills Inderal
    Buy Inderal no Prescription
    Purchase Inderal COD
    Alternative Purchase Inderal
    Purchase no Prescription Inderal
    Order Lasix no Prescription
    Purchase Lasix COD
    Purchase Lasix Without a Prescription
    Buying Lasix Without Prescription
    Tablets Purchase Lasix
    Buy no Prescription Levaquin
    Buy Levaquin Next Day Delivery
    Take no Prescription Levaquin
    Purchase Levaquin Generic
    Buy Alternative Levaquin
    Buying Lexapro no Prescription
    Generic Buying Lexapro
    Purchase Lexapro COD
    Purchase Lexapro no Prescription
    Tablets Purchase Lexapro
    Buy Lipitor Free Delivery
    Order Lipitor no Prescription
    Online Buy Lipitor Without a Prescription
    Tablets Buying Lipitor
    Generic Purchase Lipitor
    Purchase Lisinopril Free Delivery
    Purchase Lisinopril Alternative
    Take Lisinopril Without Prescription
    Online Order Lisinopril Without Prescription
    Tablets Buying Lisinopril
    Alternative Order Methotrexate
    Purchase Methotrexate COD
    Why Take Methotrexate
    Purchase Methotrexate Online Without Prescription
    Purchase Methotrexate Online no Prescription
    Cheapest Buy Nizoral
    Order Nizoral Free Delivery
    Purchase Nizoral by Phone
    Alternative Order Nizoral
    Purchase Nizoral Drug
    Take Nolvadex Without Prescription
    Cheapest Order Nolvadex
    Take Nolvadex Drug
    Purchase Online no Prescription Nolvadex
    Purchase Nolvadex Medication
    Nortriptyline Antidepressant
    Buy Tablets Nortriptyline Online
    When to Take Nortriptyline
    Purchase Nortriptyline Pills
    Buying Without Prescription Nortriptyline
    Tablets Buy Ortho Tri-Cyclen
    Order Ortho Tri-Cyclen Generic
    Take no Prescription Ortho Tri-Cyclen
    Purchase Ortho Tri-Cyclen COD
    Take Ortho Tri-Cyclen Without Prescription
    Purchase Online Without a Prescription Premarin
    Pills Buying Premarin
    Tablets Buying Premarin
    Order Premarin COD
    Tablets Buy Premarin
    Buy Tablets Proscar Online
    Buy Tablets Proscar
    Buy no Prescription Proscar Online
    Purchase Proscar Alternative
    Purchase Cheapest Proscar
    Buy Risperdal by Phone
    Order Risperdal Medication
    Generic Order Risperdal
    Purchase Risperdal Online no Prescription
    Buy Risperdal Next Day Delivery
    Take Synthroid Free Delivery
    Take Synthroid Pills
    Buy Without a Prescription Synthroid
    Purchase Synthroid Alternative
    Take Synthroid Legally
    Generic Order Topamax
    Order Online Without a Prescription Topamax
    Take no Prescription Topamax
    Order Cheap Topamax
    Buy Topamax Without a Prescription
    Valtrex Acyclovir
    Pills Purchase Valtrex
    Generic Buying Valtrex
    Online Buy Valtrex Without a Prescription
    Order Valtrex COD
    Purchase Online no Prescription Zithromax
    Buy Zithromax Next Day Delivery
    Purchase Zithromax Pills
    Buy Zithromax Free Delivery
    Buying Without a Prescription Zithromax Online