From: Krasimir A. <ka2...@ya...> - 2004-11-02 07:59:43
|
--- Bjorn Bringert <d00...@dt...> wrote: > Hi Krasimir, > > the problem is in the code that you use to print the > query. You are not > actually seeing the query that gets executed since > the query is not > optimized yet. If you use > Database.HaskellDB.showSql, you will see the > optimized query. > > /Bjorn Thanks! With showSql the things are much better. Now I got: SELECT DISTINCT docDate FROM documents as T1 This is better but why is there DISTINCT keyword. Can I get the query without it? The SQL script is even worse when I have two tables in query: [****** Haskell ******] import Database.HaskellDB import Database.HaskellDB.Query import Database.HaskellDB.Sql import Database.HaskellDB.GenericConnect import Text.PrettyPrint import Testdb.Documents main = do let primQuery = do docs1 <- table documents docs2 <- table documents restrict (docs1!xid .==. docs2!xid) project (docDate << docs1!docDate # docDate << docs2!docDate) putStrLn (render (showSql primQuery)) [****** SQL ******] SELECT DISTINCT docDate1 as docDate, docDate1 as docDate FROM (SELECT DISTINCT id as id2, docDate as docDate2 FROM documents as T1) as T1, (SELECT DISTINCT id as id1, docDate as docDate1 FROM documents as T1) as T2 WHERE (id1 = id2) There are two derived tables, three distincts and one cross join. Can I get the optimal query? SELECT T1.docDate as docDate1, T1.docDate as docDate2 FROM documents as T1 JOIN documents as T2 on T1.id = T2.id Regards, Krasimir __________________________________ Do you Yahoo!? Check out the new Yahoo! Front Page. www.yahoo.com |