Is it possible to have an indexed view in MySQL?

37,360

Solution 1

I don't think MySQL supports materialized views which is what you would need, but it wouldn't help you in this situation anyway. Whether the index is on the view or on the underlying table, it would need to be written and updated at some point during an update of the underlying table, so it would still cause the write speed issues.

Your best bet would probably be to create summary tables that get updated periodically.

Solution 2

Have you considered abstracting your transaction processing data from your analytical processing data so that they can both be specialized to meet their unique requirements?

The basic idea being that you have one version of the data that is regularly modified, this would be the transaction processing side and requires heavy normalization and light indexes so that write operations are fast. A second version of the data is structured for analytical processing and tends to be less normalized and more heavily indexed for fast reporting operations.

Data structured around analytical processing is generally built around the cube methodology of data warehousing, being composed of fact tables that represent the sides of the cube and dimension tables that represent the edges of the cube.

Solution 3

Flexviews supports materialized views in MySQL by tracking changes to underlying tables and updating the table which functions as a materialized view. This approach means that SQL supported by the view is a bit restricted (as the change logging routines have to figure out which tables it should track for changes), but as far as I know this is the closest you can get to materialized views in MySQL.

Share:
37,360
Thomas Owens
Author by

Thomas Owens

Professionally, I'm a software engineer focusing on agile and lean software development and software process improvement. I work to help engineers, teams, and organizations be successful. I have experience with a wide variety of types of software, ranging from embedded systems to desktop applications to web applications. In my spare time, I'm a runner, a photographer, and a casual gamer. Find me on LinkedIn, Twitter, Reddit, Medium, GitHub, Quora, and ProjectManagement.com. Support my freely available (CC BY and CC BY-SA) content through Patreon, PayPal, Buy me a Coffee, or my Amazon Wishlist.

Updated on July 17, 2020

Comments

  • Thomas Owens
    Thomas Owens almost 4 years

    I found a posting on the MySQL forums from 2005, but nothing more recent than that. Based on that, it's not possible. But a lot can change in 3-4 years.

    What I'm looking for is a way to have an index over a view but have the table that is viewed remain unindexed. Indexing hurts the writing process and this table is written to quite frequently (to the point where indexing slows everything to a crawl). However, this lack of an index makes my queries painfully slow.