From: Bjorn B. <d00...@dt...> - 2004-11-01 15:27:37
|
Krasimir Angelov wrote: > I interested to see the generated SQL code from > HaskellDB. The first step was to write very simple > example: > > 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 = runQuery $ do > docs <- table documents > project (docDate << docs!docDate) > putStrLn (render (ppSql (toSql primQuery))) > > When the example was executed I got: > > SELECT DISTINCT docDate2 as docDate > FROM (SELECT DISTINCT docDate1 as docDate2, > id1, > docDate1, > creationDate1 > FROM (SELECT DISTINCT id as id1, > docDate as docDate1, > creationDate as > creationDate1 > FROM documents as T1) as T1) as T1 > > I am surprised from this very complicated and > inefficient code. What is the reason to have these > nested "DISTICT" statements? I expected to see just > something like: > > select docDate from documents 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 |