Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I think you've overnormalized. You don't need task_start, task_finish, task_cancel junction tables. You've just traded trying to enforce UserID NOT NULL IF Status NOT NULL for enforcing that a task appears at most once in the UNION of the three task_{start,finish,cancel} tables, which will be even more awkward to code in your data dictionary (1=COUNT(*) FROM UNION...)

    You need just one task_status table that has NOT NULL FKs to TaskID and UserID, plus a State enumerated type and an autoinsert date timestamp field. The status is the State that matches max(Stamp).

    This is an INSERT-only, no UPDATE table that collects history. This is good if you have SarbOx or other audit-trail requirements; DB privilege grants can enforce this.

    If you want to avoid nested queries, you need transactions, and add an Latest boolean column that is inserted true and cleared false when updating status by inserting a new status record. In this case, a stored proc with this transaction should be the only allowed way to insert, to assure the invariant predicate of only one active state per task.

    In either case, defining a VIEW that sees only the Latest=TRUE rows (and perhaps another for Latest=TRUE and NOT State=FINISHED) will make life easier for folks building dashboards or reports.

    As you'd defined it, TaskID FK is the sole primary key, as each task has but one user; you were splitting only to allow requiring UserID NOT NULL IF State NOT NULL. Making it a history log requires Primary Key (TaskID,Stamp). But splitting state out to a side table allows the possibility of multiple users working a task in parallel or in relay, in which case primary key is (TaskID,UserID,Stamp). That this normalization gives us extra flexibility suggests it's a good one.

    --
    Bill
    # I had a sig when sigs were cool
    use Sig;
    • Ah, thanks. You're correct that my normalization wasn't correct. I can now see the value of what you propose and that does make the task simpler and more maintainable. As a caveat, though, some of what you suggest implies using a real database, not a toy like MySQL (which is what we're using).

      This gives me another good rule of thumb to keep in mind. Naturally, when I see things like field_1, field_2, field_3 and so on, it's obvious that I need another table as what I'm looking at is essentially an arr

      • You have to use a real programming language too, not a toy like Perl.

        (Oh, I meant Perl version 2. What? There's a newer version? I bet it's a toy just like Perl 2.)

      • As a caveat, though, some of what you suggest implies using a real database, not a toy like MySQL (which is what we're using).

        Can you upgrade your MySQL to the latest & greatest? Yes, MySQL3 with default engine MyISAM is a toy. MySQL5.[01] with InnoDB engine (or BDB, or the coming Falcon engine) is no longer a toy -- subquery, views, transactions. (They've even got a cluster engine for partitioning.) [ Engines [mysql.com]] (I think this is the point of the Perl 2 joke.)

        Barbie is correct that normalizing is hard

        --
        Bill
        # I had a sig when sigs were cool
        use Sig;
        • Bill nails it. I stopped having any sympathy for people who refuse to upgrade to new versions of free software at approximately 7 am on Sunday morning.

          • Bill nails it. I stopped having any sympathy for people who refuse to upgrade to new versions of free software at approximately 7 am on Sunday morning.

            What happened Sunday? I don't see a journal entry for Sunday. Is there a new entry for stupid customer tricks?

            Memo to self: update home servers to Ubuntu to 6.06LTS and Debian to 3.1 now that they're really stable ...

            --
            Bill
            # I had a sig when sigs were cool
            use Sig;
            • I read yet another Nicholas Clark "This isn't fun anymore, and no one seems to want to pay someone to fix Perl 5" message on p5p. That's when I decided that companies which rely on Perl 5 but don't send bug reports or test snapshots and have all of their code in the Darkpan can fix their own bugs, or at least pay for the continued development of Perl. That is, they can do that if they care about their code.

              • "companies which rely on Perl 5 but don't send bug reports or test snapshots and have all of their code in the Darkpan can fix their own bugs, or at least pay for the continued development of Perl. That is, they can do that if they care about their code."

                That hits home.

                Support: I tried to get commercial support for Perl, and couldn't. Yes, I could pay for it, but I couldn't get anything I could recognize as support. I talked to ActiveState at LinuxWorld 2005, interested in buying support fo

                --
                Bill
                # I had a sig when sigs were cool
                use Sig;
    • Bill pointed you in the same direction I was going to. Statuses accumulate over time, and you're typically only interested in the most recent one, unless you're rolling back time for audit purposes. But if you're stepping into an area where auditing might be a concern, you have to start paying attention to the distinction between "actual" time and "record" time (a distinction that can tie your brain in little knots when you try to think through queries). Martin Fowler has a decent intro to the issues [martinfowler.com].