Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

The fastest way to improve a slow MySQL or MariaDB query is usually not to add an index blindly. Capture the real query, inspect its execution plan with EXPLAIN, add the narrowest index that matches its predicates and ordering, then measure again on representative data. A useful index can reduce the rows the server examines; an unnecessary one consumes storage and makes every write more expensive.

What an index does—and why it can make a query faster

An index is a separate, ordered access path to table data. Instead of reading every row and testing its values, the optimizer can navigate the index entries that match a predicate and then fetch only the relevant rows. MySQL describes indexes as pointers to table rows and identifies indexes on columns tested by a query as the primary way to improve SELECT performance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Indexes can help with:

  • Filtering in WHERE clauses
  • Matching join conditions
  • Producing rows in ORDER BY order
  • Grouping in some GROUP BY plans
  • Covering a query so the base table does not need to be read

They are not universally faster. If a predicate matches most of a table, traversing an index and then fetching a large proportion of the rows can cost more than a sequential scan. Small tables and low-selectivity columns often produce the same result: the optimizer deliberately chooses a scan.

Start with the query, not the table

Indexing every column mentioned in a schema is a common mistake. Begin with a real slow query and document all of the work it asks the server to do:

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.
  • Columns in WHERE predicates, including equality and range conditions
  • Join keys and the table accessed first
  • ORDER BY and GROUP BY expressions
  • Columns returned by the SELECT list
  • Typical parameter values and how many rows the query usually returns
  • Whether the query runs occasionally or sits on a write-heavy request path

This workload description determines whether a single-column, composite, or covering index is appropriate. A column that is useful for one report may be a poor index for a high-volume transaction query.

Inspect the plan before changing the schema

Run EXPLAIN against the exact statement before adding an index:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
EXPLAIN SELECT order_id, total
FROM orders
WHERE customer_id = 42;

For versions that provide an analyzed-plan facility, use the version-appropriate analyzed form when you need observed execution details rather than estimates. Save the pre-change plan so you can compare it with the post-change plan.

What to examine in EXPLAIN

  • Access type: The access method indicates whether the server is doing a point lookup, an index range, a broader index scan, or a table scan. More selective access is generally preferable, but the best method depends on how many rows qualify.
  • Key: This is the index the optimizer selected. A null or empty key means no index was chosen for that table access.
  • Estimated rows: Compare the number of rows the plan expects to examine with the number the query returns. A large gap can indicate stale statistics or data distributions the optimizer does not understand well.
  • Filtering and extra work: Remaining filtering, temporary structures, or explicit sorting can show that an index is only partially solving the query.
  • Join order and keys: An index on a joined column is useful only if it supports the access path chosen for the other tables.

MariaDB documentation specifically recommends using EXPLAIN to determine whether indexes are being used effectively. MySQL likewise uses the plan to decide among indexes, ranges, joins, sorting, and scans; creating an index does not force the optimizer to use it.

Choosing a single-column index

A single-column index is suitable when a recurring predicate or join key is selective and does not need a second column to complete the access path.

CREATE INDEX idx_orders_customer_id
  ON orders (customer_id);

EXPLAIN
SELECT order_id, total
FROM orders
WHERE customer_id = 42;

Use this when customer_id = 42 excludes enough rows to justify indexed access. Confirm the result with EXPLAIN: the optimizer can still choose a scan for a small table or for a value that occurs in a large fraction of the table. A frequently queried column with only two possible values, for example, may provide little filtering benefit by itself.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

Designing composite indexes

A composite index stores several columns in a defined order. That order is significant. The index can generally support its leftmost prefix: an index on (tenant_id, status, created_at) is naturally useful for lookups beginning with tenant_id, but a query filtering only on status cannot normally jump directly to the relevant section because the values are interleaved under different tenants.

Match recurring predicates and ordering

For a query that filters by customer and status and then returns the newest rows, a candidate index is:

CREATE INDEX idx_orders_customer_status_date
  ON orders (customer_id, status, created_at);

EXPLAIN
SELECT order_id, created_at
FROM orders
WHERE customer_id = 42
  AND status = 'paid'
ORDER BY created_at DESC
LIMIT 50;

The first two columns match equality predicates, while the final column matches the requested ordering within that filtered subset. This is a design heuristic, not a universal formula. Test the actual plan because selectivity, data distribution, sort direction, inequalities, joins, and optimizer version can change the best choice.

Equality, range, and sort columns

As a starting point, place columns used in equality predicates and joins before columns used for ranges or ordering when that reflects the workload. A range condition often limits how much of the remaining index can be used for precise navigation. For example, an index beginning with a tenant identifier can isolate one tenant before applying a date range. If another query commonly filters by date alone, it may need a different leading column; do not contort one index to serve unrelated query shapes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leftmost-prefix checks

Before creating a composite index, list the query forms it must serve:

Index Can naturally support Usually cannot use the leading access path for
(tenant_id, status, created_at) Tenant; tenant plus status; tenant plus status plus date; tenant-scoped ordering by date Status alone; date alone; status plus date without tenant
(customer_id, status, created_at) Customer; customer plus status; customer/status filtered date ordering Status alone or date alone

“Can support” still means “may support.” The optimizer can reject an available index when a scan or another index has a lower estimated cost.

Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

Covering indexes: fewer row lookups at a higher cost

A covering index contains every column needed to filter and return a query. When the engine can satisfy the statement from index entries alone, it may avoid fetching the corresponding base-table rows.

CREATE INDEX idx_orders_customer_status_date_total
  ON orders (customer_id, status, created_at, total);

This can cover a query that filters on customer_id and status and selects only order_id, created_at, and total only if every selected column, including order_id, is actually present in the index or is available through the table’s index structure. Check the plan rather than assuming coverage.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Covering indexes trade read savings for a wider structure. Every added column increases index storage, cache pressure, and the amount of work required on INSERT, UPDATE, and DELETE. MariaDB guidance also notes that prefix indexes cannot provide covering behavior, because a prefix stores only part of a value.

A repeatable indexing workflow

  1. Capture the slow statement. Include representative parameter values, joins, sort and grouping clauses, and the columns returned. A query copied from a log is more useful than a hypothetical table-wide index plan.
  2. Record the baseline plan. Run EXPLAIN SELECT ... and, where supported by your server version, an analyzed-plan variant. Record the chosen key, access method, estimated rows, join order, filtering, and sort or temporary operations.
  3. Propose the narrowest useful index. Choose a single-column index when one selective predicate is enough. Choose a composite index when several predicates, a join and an ordering pattern recur together. Apply the leftmost-prefix rule before building it.
  4. Create the index in a controlled change. Account for table size, available online-DDL options, replication, lock behavior, and maintenance windows appropriate to your MySQL or MariaDB version and storage engine.
  5. Run EXPLAIN again. Confirm whether the new index is selected and whether estimated rows, filtering, sorting, or temporary work improve. An index that exists but is never chosen has not solved the problem.
  6. Measure on representative data. Compare execution time and rows examined under realistic parameters, cache conditions, and concurrency. Do not claim a percentage improvement without a reproducible workload benchmark.
  7. Check write paths and storage. Monitor insert, update, and delete latency, index size, buffer-pool or cache pressure, and replication impact. A read improvement may be a poor trade if it harms a write-heavy workload.
  8. Refresh statistics when needed. Run ANALYZE TABLE when data distribution changes substantially or plans become stale, following the behavior and operational guidance for your server version.
  9. Consolidate only after dependency checks. Before dropping a seemingly redundant index, inspect all important queries and plans. Two indexes that look similar may have different leading columns or may support different ordering and covering requirements.

Why an index is ignored

The predicate is not selective

If a value matches most rows, an index may require nearly as many row fetches as a scan. The optimizer can correctly decide that scanning is cheaper.

The query does not use the leftmost prefix

An index beginning with (tenant_id, status) is not a general-purpose index for WHERE status = 'paid'. Create a different leading order only when that query pattern is important enough to justify another structure.

An expression or incompatible comparison hides the indexed value

Wrapping a column in a function, applying a transformation, or comparing incompatible data types can prevent ordinary index use or reduce its usefulness. Rewrite the predicate where semantics permit, or use the expression/indexing features supported by your exact server version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

Statistics are stale

The optimizer relies on cardinality estimates. After major data changes, ANALYZE TABLE can refresh statistics so the chosen plan reflects current distributions.

The query returns too many columns or rows

A narrow index may find candidate keys but still require extensive base-table reads. A covering design can help a small projection, but widening the index is worthwhile only if the read savings exceed its storage and write costs.

Sorting or grouping does not match the index

A composite index can help ORDER BY or GROUP BY only when the preceding columns and directions line up with the query’s usable prefix. Otherwise the server may still sort or create a temporary structure.

Indexes and write performance

Every secondary index must be maintained when indexed column values or rows change. More indexes therefore mean more page writes, logging, storage, cache use, and potentially longer schema changes. The cost is especially visible on tables with frequent inserts or updates.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Review indexes as a set:

  • Find indexes with the same leading columns and determine whether one makes another unnecessary.
  • Keep indexes required by foreign-key, uniqueness, join, reporting, and ordering workloads.
  • Remove or consolidate only after checking production plans and less frequent queries.
  • Prefer the smallest column set that satisfies the measured workload; do not add every selected column automatically.

MySQL and MariaDB: a practical comparison

The core method is the same in both systems: design around real predicates, respect composite-index order, and validate with EXPLAIN. Feature names, optimizer behavior, analyzed-plan syntax, online DDL capabilities, and statistics details can differ by release, so use the documentation for the exact MySQL or MariaDB version in production.

Decision point How to evaluate it
Predicate and join selectivity Estimate how many rows qualify for typical values; low selectivity may favor a scan.
Usable leftmost prefix Check that important query forms begin with the composite index’s first columns.
Ordering and grouping Verify whether the index can produce the requested order or avoid a temporary operation.
Covering potential Confirm every required filter and projected column is available in the index; account for index width.
EXPLAIN estimates and access type Compare chosen key, rows, filtering, joins, and extra operations before and after.
Storage and write maintenance Measure index size and write impact, particularly on high-change tables.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common mistakes to avoid

  • Indexing every column mentioned in a query: A query may use one composite path more effectively than several isolated indexes, and unused indexes still cost writes.
  • Assuming the newest index must be used: The optimizer chooses the least expensive estimated plan, not the most recently created object.
  • Putting columns in a memorized “best” order: Equality-first is a useful starting heuristic, but workload selectivity and ordering requirements decide the final design.
  • Testing on an empty or tiny table: A scan can be correct there while production-scale data benefits from an index.
  • Ignoring returned columns: A filter may be efficient while a large projection still causes many table reads.
  • Dropping indexes without plan checks: A rarely observed report or join can depend on an index that appears redundant from one query’s perspective.
  • Expecting a guaranteed speedup: There is no universal percentage improvement; results depend on schema, data distribution, server version, hardware, concurrency, and parameter values.

Worked decision example

Suppose an application repeatedly requests the 50 newest paid orders for one customer. The query filters on customer_id and status, orders by created_at, and returns a small projection. Start by examining the baseline plan. If it scans orders and sorts a large candidate set, test (customer_id, status, created_at). If the post-change plan still performs many base-table lookups and the projection is stable and small, test a covering variant that adds the returned columns. Keep the wider index only if measured read savings justify its storage and write cost. If another important workload filters by status without customer, this index does not replace a status-leading design; decide whether that separate workload merits its own index.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

When indexing is not the answer

An index cannot fix every slow query. First verify that the statement is logically necessary, returns no more rows than the application needs, joins on compatible keys, and avoids avoidable computation. A poor join order, an unbounded report, stale statistics, locking, disk saturation, or an expensive sort can dominate runtime even after indexing. Use the execution plan to identify the actual bottleneck before changing the schema.

Frequently Asked Questions

How do I know whether MySQL or MariaDB is using my index?

Run EXPLAIN and inspect the selected key, access type, estimated rows, filtering, and extra sort or temporary operations. Re-run it after the index change and compare the plans.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What column order should a composite index use?

Follow the recurring query shape: commonly place equality and join columns first, then range or ordering columns, while checking the leftmost-prefix rule. Validate the proposed order with EXPLAIN; there is no universal ordering formula.

Why does the optimizer choose a table scan even though an index exists?

A scan may be cheaper when the predicate is low-selectivity, the table is small, statistics are stale, the query does not use the index’s leftmost prefix, or many base-table rows would still need to be fetched.

Should I create a covering index for every slow query?

No. Covering indexes can avoid row lookups, but every included column increases index size and write-maintenance cost. Add one only when measured read savings justify that trade-off.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.