{"id":31744915,"url":"https://github.com/roadsideseb/mti-lightbulb","last_synced_at":"2025-10-09T12:28:09.121Z","repository":{"id":10762860,"uuid":"13025868","full_name":"roadsideseb/mti-lightbulb","owner":"roadsideseb","description":"Testing how different aproaches to multi table inheritance and alternatives through the Django ORM.","archived":false,"fork":false,"pushed_at":"2013-12-16T12:50:03.000Z","size":596,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-04-16T03:32:53.341Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/roadsideseb.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-09-23T03:11:13.000Z","updated_at":"2024-04-16T03:32:53.341Z","dependencies_parsed_at":"2022-09-14T11:41:30.883Z","dependency_job_id":null,"html_url":"https://github.com/roadsideseb/mti-lightbulb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/roadsideseb/mti-lightbulb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadsideseb%2Fmti-lightbulb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadsideseb%2Fmti-lightbulb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadsideseb%2Fmti-lightbulb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadsideseb%2Fmti-lightbulb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roadsideseb","download_url":"https://codeload.github.com/roadsideseb/mti-lightbulb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roadsideseb%2Fmti-lightbulb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001445,"owners_count":26083078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-09T12:28:03.909Z","updated_at":"2025-10-09T12:28:09.112Z","avatar_url":"https://github.com/roadsideseb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"=============\nMTI Lightbulb\n=============\n\n.. image:: https://d2weczhvl823v0.cloudfront.net/elbaschid/mti-lightbulb/trend.png\n\n**Disclaimer:** this is a small research project and is currently under\ndevelopment so there might be changes at any point in time. It is also not\ncomplete and there are things that will break. Use with care :)\n\nWhenever you hear experienced Django developers talk about using Django's\nmodels and define content structures, they tell you that *multi-table\ninheritance* (MTI) is bad. Looking at the SQL statements that are generated by\nthe ORM, you'll see some nasty ``LEFT INNER JOIN`` s in there. The question that\nbugged my, however, was **how** bad is it actually, when does it become a real\nperformance problem and what are the alternatives. \n\nThis project is my opinionated attempt to shed some light and provide a some\nalternative suggestions for MTI. This is most likely not a generic solution and\nit is not trying to be. The structure I used is driven by the project that\ntriggered this investigative process: `django-fancypages`_.\n\n.. image:: https://raw.github.com/elbaschid/mti-lightbulb/master/docs/_static/images/plot_mti_vs_generic_m2m.png\n\nI'll provide more details on my approach, the results and how to run the tests\nas I get some more time to work on this...be patient and check back soon...\n\n.. _`django-fancypages`: https://github.com/tangentlabs/django-fancypages\n\nSetting it all up\n-----------------\n\nTo try this out, follow these steps to setup you local copy of the projects.\nClone the repo locally::\n\n    git clone https://github.com/elbaschid/mti-lightbulb.git\n\nNow install all the dependencies for the project by running::\n\n    pip install -r requirments_dev.txt\n\nThis will probably take a while since it will also install some dependencies\nsuch as ``numpy`` and ``matplotlib`` for investigating the data.\n\nAfter the installation you are almost ready to go. I've tried all this in a\nvagrant box and setting one up yourself is the easiest way to get going. If you\ndon't have vagrant or want to use your own setup, change the configuration in\n``lightbulb/settings.py`` manually.\n\nTo get a working vagrant box up and running make sure that you have vagrant\ninstalled. If you don't follow the installation guide `on the Vagrant\nwebsite`_. You also have to make sure that you have the ``precise64`` base box\navailable and the vagrant plugin for salt provisioning. Get the base box::\n\n    vagrant init precise64 http://files.vagrantup.com/precise64.box\n\nand then add the plugin for salt to your vagrant installation::\n\n    vagrant plugin install vagrant-salt\n\nNow you can setup a new box, this will take some time since it will install a\nfew requirements and set up a PostgreSQL database::\n\n    vagrant up\n\nYou are ready to play with it!\n\n\nRunning the benchmark\n---------------------\n\nThere are currently two apps available that can be used for testing. \n\n1. ``multi_table``: which tests multi-table inheritance using the\n   `django-model-utils`_ package\n\n2. ``generic_m2m``: which uses the `django-generic-m2m`_ app to handle a\n   Many2Many relationship for generic foreign keys.\n\n\nRunning a benchmark on either one of those test apps is implemented in the\n``benchy`` app as a management command. Using the basic set up you would run a\ntest on multi-table inheritance using::\n\n    ./manage.py run_benchmark multi_table\n\nThis will run DB queries against database models starting with 1 model going up\nto 500 in steps of 5 (default setting). You can change these by providing\n``--num-block 200`` or ``--step-size 1``. By default, a timestamped CSV file is\ncreated and the results of each iteration is printed to the console as well (so\nyou see some progress).\n\n**Spoiler/Warning:** I've run this on a Digital Ocean box with 1GB of RAM and\nthe MTI test crashes the DB server when using 100 blocks because it uses up all\nthe memory. So be careful with that :)\n\n\nFeedback \u0026 Contributions\n------------------------\n\nI appreciate any feedback on the way I am approaching this, how it's\nimplemented. If you have any input on this feel free to file an issue on github\nor send me an email.\n\n.. _`on the Vagrant website`: http://docs.vagrantup.com/v2/installation/index.html\n.. _`django-model-utils`: https://github.com/carljm/django-model-utils\n.. _`django-generic-m2m`: https://github.com/coleifer/django-generic-m2m\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froadsideseb%2Fmti-lightbulb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froadsideseb%2Fmti-lightbulb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froadsideseb%2Fmti-lightbulb/lists"}