Showing posts from May, 2007

MySQL Optimizer Bug 28554

When we tried to clean up a rather large (4.500.000 rows, 20GB) InnoDB table some days ago, we were astonished by the time MySQL took to complete the task. We had already LIMIT ed the transaction size, but every single chunk still took minutes to execute. The table itself contains some number columns, including a numeric primary key, and a blob. The delete condition was mainly based on the primary key (being smaller than a predefined value) and status field. After some mails between the support crew and us an optimizer bug was identified: MySQL Bug #28554 . The problem is that in some cases the optimizer makes a bad choice concerning which index to use. It will pick a secondary index that can be used to cover a WHERE indexed_column=<constant> condition, even though it will cause way more data to be scanned than necessary. The primary key for the second condition pk_column<=<constant> would be a far better choice, visiting only a much smaller number of rows. The bug h

USB scanner not working on VMwared XP

I recently changed my health-insurance company. Today I got a letter asking me to return my insurance card or notify them in case I destroyed it myself. So I thought I might just fax them an image of the destroyed card. Because Fritz!Fax works beautifully in my virtual XP box, I wanted to get my Canon LiDE Scan 70 installed in the VM (no Linux support...). I downloaded the most recent driver from Canon's website and installed it. Unfortunately I only get blue screens as soon as I "connect" the scanner to the virtual machine using the VMware server console. Being somewhat disappointed I will now have to boot up the RealThing(TM) Windows partition again...

Linux EventQueue Problem

As a part of an ongoing project I had to write a little on-screen keyboard. It is a very simple thing: Just a panel consisting of a series of JButtons that - when clicked - insert KeyEvents into the EventQueue to enable any Swing text component to be used. I do not have the original code at hand right now, but I reconstructed it at home: import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import javax.swing.*; public class TestTool extends JFrame { private JTextArea textArea; private JButton btnA; private JButton btnB; private KeyEvent createEvent(Component aSrc, char aChar) { return new KeyEvent(aSrc, KeyEvent.KEY_TYPED, System .currentTimeMillis(), 0, 0, aChar); } ActionListener btnLstn = new ActionListener() { public void actionPerformed(ActionEvent e) { EventQueue q = Toolkit.getDefaultToolkit().getSystemEventQueue(); if (e

MySQL: Add primary key to table with duplicates

Maybe this is obvious, but I post it anyway, just to remind myself should I need it again. Recently I had to change a table that I had not completely thought through when I first created it. The structure was so simple, I did not think I could do anything wrong with it: CREATE TABLE `parent` ( `par_id` bigint(20) NOT NULL, `somevalue` varchar(20) default NULL, PRIMARY KEY (`par_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `child` ( `x_parid` bigint(20) default NULL, `value` bigint(10) default NULL, KEY `fk_parid` (`x_parid`), CONSTRAINT `child_ibfk_1` FOREIGN KEY (`x_parid`) REFERENCES `parent` (`par_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; There is a 1:0..* relationship between parent and child. Some sample data: mysql> select * from parent; +--------+--------------+ | par_id | somevalue | +--------+--------------+ | 1 | Parent No. 1 | | 2 | Parent No. 2 | | 3 | Parent No. 3 | +--------+--------------+ 3 rows in set (0.00

FindBugs - Writing custom detectors (Part 2)

This is the second part of the "Howto write a FindBugs Bug Detector" (see the first part here ). To understand why one would write the kind of detector mentioned here, you should read the first part if you do not already know it. Last time I presented a detector that is able to detect static fields of the types java.util.Calendar and java.text.DateFormat . While declaring fields like this may be suspicious, there is not necessarily something wrong with the code. The real danger comes from calling methods on suchlike fields, especially if they are not synchronized to protect them against concurrent access. So in this article we will extend and improve the existing detector to cope with this problem. Something to chew on This a simple class that uses a static Calendar instance. It does not really do much, but the shorter the program, the easier to understand its bytecode (this is what we need to do this time). import java.util.Calendar; public class StaticCalendarSample3

SAP MemoryAnalyzer

SAP's Markus Kohler wrote a blog entry about their Memory Analyzer tool I blogged about some days ago. It includes a flash based walk-through video about its core features. It also includes a download link. I did not try to download, because I have the DVD from jax.07. The blog says "for free", so I am not sure if the tool is really limited to a 30 day trial (as is the Netweaver Composition Environment which includes it).