diff -ur postfix-2.1.1.orig/src/global/dict_mysql.c postfix-2.1.1/src/global/dict_mysql.c
--- postfix-2.1.1.orig/src/global/dict_mysql.c	2004-04-01 07:30:05.000000000 +0900
+++ postfix-2.1.1/src/global/dict_mysql.c	2004-05-19 23:44:48.000000000 +0900
@@ -135,6 +135,7 @@
 
 /* Application-specific. */
 
+#include "mac_parse.h"
 #include "dict_mysql.h"
 
 /* need some structs to help organize things */
@@ -164,6 +165,7 @@
     char   *select_field;
     char   *where_field;
     char   *additional_conditions;
+    char   *direct_query;
     char  **hostnames;
     int     len_hosts;
 } MYSQL_NAME;
@@ -198,7 +200,23 @@
 static MYSQL_NAME *mysqlname_parse(const char *);
 static HOST *host_init(const char *);
 
-
+typedef struct {
+    const char *key;
+    VSTRING *query;
+} DICT_MYSQL_PARSE_ARG;
+ 
+static int parse_callback(int type, VSTRING *buf, char *context)
+{
+    DICT_MYSQL_PARSE_ARG *arg = (DICT_MYSQL_PARSE_ARG *)context;
+
+    if (type == MAC_PARSE_LITERAL)
+	vstring_strcat(arg->query, vstring_str(buf));
+    else if (type == MAC_PARSE_VARNAME) {
+	if (strcmp(vstring_str(buf), "key") == 0)
+	    vstring_strcat(arg->query, arg->key);
+    }
+    return 0;
+}
 
 /**********************************************************************
  * public interface dict_mysql_lookup
@@ -228,9 +246,16 @@
     }
     /* prepare the query */
     mysql_escape_string(name_escaped, name, (unsigned int) strlen(name));
-    vstring_sprintf(query, "select %s from %s where %s = '%s' %s", dict_mysql->name->select_field,
-       dict_mysql->name->table, dict_mysql->name->where_field, name_escaped,
+    if (dict_mysql->name->direct_query[0]) {
+	DICT_MYSQL_PARSE_ARG arg;
+	arg.key = name_escaped;
+	arg.query = query;
+	mac_parse(dict_mysql->name->direct_query, parse_callback, (char *)&arg);
+    } else {
+	vstring_sprintf(query, "select %s from %s where %s = '%s' %s", dict_mysql->name->select_field,
+	   dict_mysql->name->table, dict_mysql->name->where_field, name_escaped,
 		    dict_mysql->name->additional_conditions);
+    }
     if (msg_verbose)
 	msg_info("dict_mysql_lookup using sql query: %s", vstring_str(query));
     /* free mem associated with preparing the query */
@@ -512,14 +537,17 @@
     /* database name */
     name->dbname = cfg_get_str(name->parser, "dbname", "", 1, 0);
 
+    /* direct query */
+    name->direct_query = cfg_get_str(name->parser, "direct_query", "", 0, 0);
+
     /* table name */
-    name->table = cfg_get_str(name->parser, "table", "", 1, 0);
+    name->table = cfg_get_str(name->parser, "table", "", name->direct_query[0] ? 0 : 1, 0);
 
     /* select field */
-    name->select_field = cfg_get_str(name->parser, "select_field", "", 1, 0);
+    name->select_field = cfg_get_str(name->parser, "select_field", "", name->direct_query[0] ? 0 : 1, 0);
 
     /* where field */
-    name->where_field = cfg_get_str(name->parser, "where_field", "", 1, 0);
+    name->where_field = cfg_get_str(name->parser, "where_field", "", name->direct_query[0] ? 0 : 1, 0);
 
     /* additional conditions */
     name->additional_conditions = cfg_get_str(name->parser,
@@ -637,6 +665,7 @@
     myfree(dict_mysql->name->select_field);
     myfree(dict_mysql->name->where_field);
     myfree(dict_mysql->name->additional_conditions);
+    myfree(dict_mysql->name->direct_query);
     for (i = 0; i < dict_mysql->name->len_hosts; i++) {
 	myfree(dict_mysql->name->hostnames[i]);
     }
