Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 183351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:06:01+00:00 2026-05-11T15:06:01+00:00

Due to performance reasons I can’t use the ORM query methods of Django and

  • 0

Due to performance reasons I can’t use the ORM query methods of Django and I have to use raw SQL for some complex questions. I want to find a way to map the results of a SQL query to several models.

I know I can use the following statement to map the query results to one model, but I can’t figure how to use it to be able to map to related models (like I can do by using the select_related statement in Django).

model_instance = MyModel(**dict(zip(field_names, row_data))) 

Is there a relatively easy way to be able to map fields of related tables that are also in the query result set?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:06:01+00:00Added an answer on May 11, 2026 at 3:06 pm

    First, can you prove the ORM is stopping your performance? Sometimes performance problems are simply poor database design, or improper indexes. Usually this comes from trying to force-fit Django’s ORM onto a legacy database design. Stored procedures and triggers can have adverse impact on performance — especially when working with Django where the trigger code is expected to be in the Python model code.

    Sometimes poor performance is an application issue. This includes needless order-by operations being done in the database.

    The most common performance problem is an application that ‘over-fetches’ data. Casually using the .all() method and creating large in-memory collections. This will crush performance. The Django query sets have to be touched as little as possible so that the query set iterator is given to the template for display.

    Once you choose to bypass the ORM, you have to fight out the Object-Relational Impedance Mismatch problem. Again. Specifically, relational ‘navigation’ has no concept of ‘related’: it has to be a first-class fetch of a relational set using foreign keys. To assemble a complex in-memory object model via SQL is simply hard. Circular references make this very hard; resolving FK’s into collections is hard.

    If you’re going to use raw SQL, you have two choices.

    1. Eschew ‘select related’ — it doesn’t exist — and it’s painful to implement.

    2. Invent your own ORM-like ‘select related’ features. A common approach is to add stateful getters that (a) check a private cache to see if they’ve fetched the related object and if the object doesn’t exist, (b) fetch the related object from the database and update the cache.

    In the process of inventing your own stateful getters, you’ll be reinventing Django’s, and you’ll probably discover that it isn’t the ORM layer, but a database design or an application design issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 339k
  • Answers 339k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to translate the origin to the point you… May 14, 2026 at 4:34 am
  • Editorial Team
    Editorial Team added an answer If you are holding long enough to turn the device… May 14, 2026 at 4:34 am
  • Editorial Team
    Editorial Team added an answer The size of an integer All columns in SQLite databases… May 14, 2026 at 4:34 am

Related Questions

Due to performance reasons I can't use the ORM query methods of Django and
I'm maintaining an in-house ORM written in C#, and it currently does not have
I always wondered why automatic setting of the pointer to NULL after delete is
I'm working on a large scale performance critical asp web application with a pretty
I use temporary tables in an SQLite based iPhone application. Performance was not as

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.