Hi all

I have a problem getting a large amount of data using NHibernate
Below, you can see 3 methods wich do exactly the same. They select
records (with 5 fields) from the database. The response times
mentioned are for a case where I get aproximately 200.000 rows.
The first method puts each record in a special Entity and makes a list
of those Entities (time: 1min40sec).
I wrote the second method because the first one was too slow. It does
the same but just puts each record in an object array and return a
list of object arrays (time: 50sec).
This was also too slow for me. So just for testing, I wrote the third
(very ugly, I know) method which doesn't use NHibernate. Only the
third method has a response time to my liking (time: 5sec).
Can anyone explain why there is such a big difference in response
times? What could I be doing wrong? Or do have to live with it (I
don't think I can ;-) )

Any ideas?

Methods:

//2 times slower than Untyped (1min40sec)
        public List<BenchmarkData> FindBenchmarkDataForSurvey(string
surveyName, string surveyVersion, int kbModelId, int
cuQuestionnaireId)
        {
            string sqlQueryString =
                String.Concat(
                    "SELECT ifs.is_name as {bd.SurveyName},
ifs.is_version as {bd.SurveyVersion}, ",
                    "CONVERT(VARCHAR(25) , ds.cu_resp_id) as
{bd.Id.Key1}, ",
                    "ivk.ivk_var_id as {bd.Id.Key2}, ",
                    "CONVERT(VARCHAR(50), ds.score_value) as
{bd.ResponseCode} ",
                    "FROM ",
                    "cu_resp_dataset ds ",
                    "JOIN cu_question cq ON ds.cu_question_id = cq.id
",
                    "JOIN kb_model_item kbmi ON cq.kb_question_id =
kbmi.kb_question_id ",
                    "JOIN kb_question kbq ON kbmi.kb_question_id =
kbq.id ",
                    "JOIN dbo.if_var_kb_question ivk ON kbq.id =
ivk.kb_question_id ",
                    "JOIN dbo.if_survey ifs ON ivk.is_id = ifs.is_id
",
                    "WHERE kbmi.kb_model_id = :kbModelId ",
                    "AND cq.cu_questionn_id = :cuQuestionnaireId ",
                    "AND ifs.is_name = :surveyName ",
                    "AND ifs.is_version = :surveyVersion ",
                    "GROUP BY ifs.is_name, ifs.is_version,
ds.cu_resp_id, ivk.ivk_var_id, ds.score_value ",
                    "ORDER BY ifs.is_name, ifs.is_version,
ds.cu_resp_id, ivk.ivk_var_id, ds.score_value"
                    );
            IQuery sqlQuery = Session.CreateSQLQuery
(sqlQueryString).AddEntity("bd", typeof(BenchmarkData)).
                SetInt32("kbModelId", kbModelId).
                SetInt32("cuQuestionnaireId", cuQuestionnaireId).
                SetString("surveyName", surveyName).
                SetString("surveyVersion", surveyVersion);
            return sqlQuery.List<BenchmarkData>() as
List<BenchmarkData>;
        }

        //2 times faster than Typed (50sec)
        public IList FindBenchmarkDataForSurveyUntyped(string
surveyName, string surveyVersion, int kbModelId, int
cuQuestionnaireId)
        {
            string sqlQueryString =
                String.Concat(
                    "SELECT ifs.is_name, ifs.is_version, ",
                    "CONVERT(VARCHAR(25) , ds.cu_resp_id), ",
                    "ivk.ivk_var_id, ",
                    "CONVERT(VARCHAR(50), ds.score_value) ",
                    "FROM ",
                    "cu_resp_dataset ds ",
                    "JOIN cu_question cq ON ds.cu_question_id = cq.id
",
                    "JOIN kb_model_item kbmi ON cq.kb_question_id =
kbmi.kb_question_id ",
                    "JOIN kb_question kbq ON kbmi.kb_question_id =
kbq.id ",
                    "JOIN dbo.if_var_kb_question ivk ON kbq.id =
ivk.kb_question_id ",
                    "JOIN dbo.if_survey ifs ON ivk.is_id = ifs.is_id
",
                    "WHERE kbmi.kb_model_id = :kbModelId ",
                    "AND cq.cu_questionn_id = :cuQuestionnaireId ",
                    "AND ifs.is_name = :surveyName ",
                    "AND ifs.is_version = :surveyVersion ",
                    "GROUP BY ifs.is_name, ifs.is_version,
ds.cu_resp_id, ivk.ivk_var_id, ds.score_value ",
                    "ORDER BY ifs.is_name, ifs.is_version,
ds.cu_resp_id, ivk.ivk_var_id, ds.score_value"
                    );
            IQuery sqlQuery = Session.CreateSQLQuery(sqlQueryString).
                SetInt32("kbModelId", kbModelId).
                SetInt32("cuQuestionnaireId", cuQuestionnaireId).
                SetString("surveyName", surveyName).
                SetString("surveyVersion", surveyVersion);
            return sqlQuery.List();
        }

        //10 times faster than via NHibernate (5sec)
        public IList FindBenchmarkDataForSurveyUntypedADO(string
surveyName, string surveyVersion, int kbModelId, int
cuQuestionnaireId)
        {
            string sqlQueryString =
                String.Concat(
                    "SELECT ifs.is_name, ifs.is_version, ",
                    "CONVERT(VARCHAR(25) , ds.cu_resp_id), ",
                    "ivk.ivk_var_id, ",
                    "CONVERT(VARCHAR(50), ds.score_value) ",
                    "FROM ",
                    "cu_resp_dataset ds ",
                    "JOIN cu_question cq ON ds.cu_question_id = cq.id
",
                    "JOIN kb_model_item kbmi ON cq.kb_question_id =
kbmi.kb_question_id ",
                    "JOIN kb_question kbq ON kbmi.kb_question_id =
kbq.id ",
                    "JOIN dbo.if_var_kb_question ivk ON kbq.id =
ivk.kb_question_id ",
                    "JOIN dbo.if_survey ifs ON ivk.is_id = ifs.is_id
",
                    "WHERE kbmi.kb_model_id = ", kbModelId, " ",
                    "AND cq.cu_questionn_id = ", cuQuestionnaireId, "
",
                    "AND ifs.is_name = '", surveyName, "' ",
                    "AND ifs.is_version = '", surveyVersion, "' ",
                    "GROUP BY ifs.is_name, ifs.is_version,
ds.cu_resp_id, ivk.ivk_var_id, ds.score_value ",
                    "ORDER BY ifs.is_name, ifs.is_version,
ds.cu_resp_id, ivk.ivk_var_id, ds.score_value"
                    );
            SqlConnection conn = new SqlConnection("Data
Source=mysource;Database=mydb;User ID=myuser;Password=mypassword;");
            SqlDataAdapter adapter = new SqlDataAdapter
(sqlQueryString, conn);
            conn.Open();
            SqlDataReader reader = adapter.SelectCommand.ExecuteReader
();
            List<object[]> list = new List<object[]>();
            while(reader.Read())
            {
                object[] record = new object[reader.FieldCount];
                record[0] = reader.GetString(0);
                record[1] = reader.GetString(1);
                record[2] = reader.GetString(2);
                record[3] = reader.GetInt32(3);
                record[4] = reader.GetString(4);
                list.Add(record);
            }
            conn.Close();
            return list;
        }



Grtz
Stif

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to