Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Performance tip on multiple selects to retrieve alot of BLOBS?

Performance tip on multiple selects to retrieve alot of BLOBS?

Scheduled Pinned Locked Moved Database
questiondatabaseperformancecode-review
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thomas ST
    wrote on last edited by
    #1

    I am retrieving a lot of data and want this to be as fast as possible. Let's say I have a database with two tables; tablePerson and tableFiles. A person has one file wich is stored in a BLOB. In my solution as it is now, I select * from person table, and while reading from this I select one row from the table with the blob.. This sums up to alot of one-row-queries towards the blob-table.. This blob-table has 678000 rows, and all these queries are taking a lot of time... So.. How can I improve performance on this? Any tips? This is something similar to my code:

    using(SqlCommand cmd = new SqlCommand("select * from tablePerson", _conn)
    {
    SqlDataReader r = cmd.exeCuteReader();

    while(r.read())
    {
    Person p = new Person();
    //read some data from columns..

    string documentID = Convert.ToString(r\["p\_docid"\]);
    p.LocationToDocument = ExtractDocument(documentID);
    

    }
    r.close();
    r.dispose();
    }

    ...

    private string ExtractDocument(string docid)
    {
    string filename = "";
    using (SqlCommand cmd = new SqlCommand("select d_docid, d_title, d_BLOB from tableDocument where d_docid=@paramDocID", _conn)
    {
    SqpParameter p = new SqlParameter("@paramDocID", System.Data.SqlDbType.Text);
    p.Value = docid;

      SqlDataReader r = cmd.exeCuteReader(System.Data.CommandBehavior.SequentialAccess);
    
      while(r.read()) //1 row..
      {
          //extract blob to a file, and set filename=that document..
      }
    

    }
    return filename;
    }

    A B 2 Replies Last reply
    0
    • T Thomas ST

      I am retrieving a lot of data and want this to be as fast as possible. Let's say I have a database with two tables; tablePerson and tableFiles. A person has one file wich is stored in a BLOB. In my solution as it is now, I select * from person table, and while reading from this I select one row from the table with the blob.. This sums up to alot of one-row-queries towards the blob-table.. This blob-table has 678000 rows, and all these queries are taking a lot of time... So.. How can I improve performance on this? Any tips? This is something similar to my code:

      using(SqlCommand cmd = new SqlCommand("select * from tablePerson", _conn)
      {
      SqlDataReader r = cmd.exeCuteReader();

      while(r.read())
      {
      Person p = new Person();
      //read some data from columns..

      string documentID = Convert.ToString(r\["p\_docid"\]);
      p.LocationToDocument = ExtractDocument(documentID);
      

      }
      r.close();
      r.dispose();
      }

      ...

      private string ExtractDocument(string docid)
      {
      string filename = "";
      using (SqlCommand cmd = new SqlCommand("select d_docid, d_title, d_BLOB from tableDocument where d_docid=@paramDocID", _conn)
      {
      SqpParameter p = new SqlParameter("@paramDocID", System.Data.SqlDbType.Text);
      p.Value = docid;

        SqlDataReader r = cmd.exeCuteReader(System.Data.CommandBehavior.SequentialAccess);
      
        while(r.read()) //1 row..
        {
            //extract blob to a file, and set filename=that document..
        }
      

      }
      return filename;
      }

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Why not do it in one select with a join?

      Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

      1 Reply Last reply
      0
      • T Thomas ST

        I am retrieving a lot of data and want this to be as fast as possible. Let's say I have a database with two tables; tablePerson and tableFiles. A person has one file wich is stored in a BLOB. In my solution as it is now, I select * from person table, and while reading from this I select one row from the table with the blob.. This sums up to alot of one-row-queries towards the blob-table.. This blob-table has 678000 rows, and all these queries are taking a lot of time... So.. How can I improve performance on this? Any tips? This is something similar to my code:

        using(SqlCommand cmd = new SqlCommand("select * from tablePerson", _conn)
        {
        SqlDataReader r = cmd.exeCuteReader();

        while(r.read())
        {
        Person p = new Person();
        //read some data from columns..

        string documentID = Convert.ToString(r\["p\_docid"\]);
        p.LocationToDocument = ExtractDocument(documentID);
        

        }
        r.close();
        r.dispose();
        }

        ...

        private string ExtractDocument(string docid)
        {
        string filename = "";
        using (SqlCommand cmd = new SqlCommand("select d_docid, d_title, d_BLOB from tableDocument where d_docid=@paramDocID", _conn)
        {
        SqpParameter p = new SqlParameter("@paramDocID", System.Data.SqlDbType.Text);
        p.Value = docid;

          SqlDataReader r = cmd.exeCuteReader(System.Data.CommandBehavior.SequentialAccess);
        
          while(r.read()) //1 row..
          {
              //extract blob to a file, and set filename=that document..
          }
        

        }
        return filename;
        }

        B Offline
        B Offline
        Bassam Saoud
        wrote on last edited by
        #3

        As Asfield said, join the 2 tables so that you retrieve them once. I would add to what he said is that you probably want to add paging. So instead of processing 1 M record, you can process 1000 record at a time etc..

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups