I wrote this script, but it's not performance-wise, so i try to improve it,

I am lack of knowledge to know how can I possible improve this

So was hoping fellow perl monks can point me into the direction so I can get a start from there.

this script is used to find the first decreased price, will get 1.67 in this case to insert to db.

3.88 1.67 1.53 1.52 + - -
i got multiple tables in database, fruit_load , fruit_pricing country zipcode city name mgroup subgroup fruit special_fruit fruit_price special_fruit_price To get the pricing for each fruit in each group in each city, zipcodeand country, I do multiple while loops,
SELECT DISTINCT (country, zipcode, city) FROM fruit_load WHERE fruit_l +oad.sold_date BETWEEN NOW() - INTERVAL 60 DAY AND NOW(); SELECT DISTINCT (owner) FROM fruit_pricing b JOIN fruit_load a ON a.fr +uit_load_id = b.fruit_load_id WHERE a.country= '$data[0]' AND a.zipco +de = '$data[1]' AND a.city = '$data[2]'; SELECT DISTINCT (mgroup) FROM fruit_pricing b JOIN fruit_load a ON a.f +ruit_load_id = b.fruit_load_id WHERE a.country = '$data[0]' AND a.zip +code = '$data[1]' AND a.city = '$data[2]' AND b.owner ='$data2[0]'; SELECT DISTINCT (fruit) FROM fruit_pricing b JOIN fruit_load a ON a. f +ruit_load_id = b. fruit_load_id WHERE a.country = '$data[0]' AND a.zi +pcode = '$data[1]' AND a.city = '$data[2]' AND b.owner = '$data2[0]' +AND b.mgroup = '$data3[0]'; SELECT * FROM fruit_load a JOIN fruit_pricing b ON a.fruit_load_id = b.fruit_load_id WHERE b.sold_date BETWEEN NOW() - INTERVAL 180 DAY AND NOW() AND a.country = '$data[0]' AND a.zipcode = '$data[1]' AND a.city = '$data[2]' AND b.owner = '$data2[0]' AND b.mgroup = '$data3[0]' AND b.fruit = '$data4[0]' ORDER BY sold_date DESC; put found row into array in this loop SELECT DISTINCT (subgroup) FROM special_fruit_price c JOIN fruit_load +a ON a.fruit_load_id = c.fruit_load_id WHERE a.country = '$data[0]' A +ND a.zipcode = '$data[1]' AND a.city = '$data[2]' AND c.owner = '$dat +a2[0]'; SELECT DISTINCT (special_fruit) FROM special_fruit_price c JOIN fruit_load a ON a.fruit_load_id = c.fruit_load_id WHERE a.country = '$data[0]' AND a.zipcode = '$data[1]' AND a.city = ' +$data[2]' AND c.owner = '$data2[0]' AND c.mgroup = '$data3[0]' AND c.subgroup = '$data6[0]'; SELECT * FROM fruit_load a JOIN special_fruit_price c ON a.fruit_load_id = c.fruit_load_id WHERE c.sold_date BETWEEN NOW() - INTERVAL 180 DAY AND NOW() AND a.country = '$data[0]' AND a.zipcode = '$data[1]' AND a.city = '$data[2]' AND c.owner = '$data2[0]' AND c.mgroup = '$data3[0]' AND c.subgroup = '$data6[0]' AND c.special_fruit = '$data7[0]' ORDER BY sold_date DESC; put found row into array in this loop
Let meknow if I can provide more information, I can give the whole code, but I try to makeit short and sweet.

The code currently run 15 mins to 2 hours varies, is it possible to shorten the time ?

I believe the multiple insert will slow down the process, at current I am trying to put them into array and insert at once.

In reply to Alternative for multiple while loops to improve performance by MissPerl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.