I would try to do as much work in the database as possible. In this case, I would create a (temporary) table with a single column containing the PK values, and join on that (which effectively filters your results). However, you are using mysql and AFAIK that database is able to do only nested-loop joins instead of the join modes far more fitting for that sort of query, so this method might actually be worse performance-wise. If the PK text file doesn't change and you need to run this query repeatedly, it may be a convenient method. Adding a column to the table containing whether it is "allowed" may be acceptable, too.

Your other option would be to emulate the hash join strategy with Perl's hashes and filter manually. There's nothing wrong with that, but it does require quite a bit of data transferred out of the database. Do note that if you do it a single record at a time, it takes little memory, as the largest thing you'll need is a hash made out of the PKs in FILE1. (Listen to the other posters, too; they make good points)


In reply to Re: Alternative to querying a database to save time by Anonymous Monk
in thread Alternative to querying a database to save time by smandape1

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.