SShortSingh.
Back to feed

When and Why Sort Direction in Database Indexes Actually Matters

0
·1 views

For single-column queries, databases like PostgreSQL, MySQL, and SQL Server can scan a B-Tree index both forward and backward with equal speed, making explicit sort direction in the index definition unnecessary. The primary benefit of indexing a sorted column is eliminating the costly filesort step, as rows are returned directly in order from the index structure. Problems arise with composite indexes when a query mixes sort directions, such as ordering one column ascending and another descending. A default composite index cannot efficiently serve mixed-direction queries, requiring the index definition to exactly match the query's ORDER BY directions. Best practice is to use a plain index for single-column sorts and reserve direction-specific composite indexes only for queries with mixed sorting requirements.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

How AI coding agent usage limits actually work and how to manage them

AI coding tools typically enforce usage limits through one of three mechanisms: token counts, request or message counts, or abstracted credits, and each model requires a different strategy to manage effectively. Many users also overlook that most tools run multiple simultaneous clocks, including a rolling short-term window and a longer billing-cycle cap, meaning a limit may reset far sooner than expected. A key technical detail is that entire conversation histories are re-sent with every turn in token-billed tools, making later turns in a session significantly more expensive than earlier ones. Rather than waiting out a reset, developers are advised to batch work into well-specified tasks upfront, since idle waiting erodes the accumulated context and problem-solving progress built during a session. Hard usage figures are intentionally omitted from this guidance, as vendor limits vary by plan and are frequently revised, making any specific numbers quickly outdated.

0
ProgrammingDEV Community ·

Structured Task Design Makes AI Coding Agents More Reliable, Study Finds

AI coding agents are increasingly capable of handling complex development work, but output quality depends heavily on how tasks are prepared and assigned. Vague instructions leave too many decisions undefined, while well-structured tasks include a clear objective, scope boundaries, constraints, and a definition of done. Developers are advised to specify not only what should change but also what must remain unchanged, such as existing API contracts or dependencies. Before work begins, teams should decide how completion will be demonstrated — through tests, screenshots, or pull requests — to avoid subjective verification. The core principle is to treat AI-assigned work as verifiable units rather than one-off prompts, with a human still responsible for confirming product intent and catching unexpected side effects.

0
ProgrammingDEV Community ·

How to Extend Claude Code with MCP, Subagents, and Hooks for Production Use

Claude Code supports external integrations through Model Context Protocol (MCP), which allows it to connect with tools and services like GitHub, Sentry, and Notion via local or hosted MCP servers. Users can add MCP servers using the 'claude mcp add' command, with options to scope access privately, across all personal projects, or shared team-wide through a repository file. Subagents enable Claude Code to delegate tasks to isolated instances with their own context, preventing the main session from being cluttered with reusable or repetitive outputs. Slash commands allow users to package frequently used prompts into reusable shortcuts, while Hooks provide deterministic guardrails that enforce rules without relying on the AI's in-session memory. Together, these four features are designed to make Claude Code a more reliable and extensible tool for production workflows.

0
ProgrammingDEV Community ·

How Outdated API Docs Silently Trained an AI Model to Write Broken Code

The team behind dailymeteo.com, a European meteorological archive, discovered that their fine-tuned GPT model had been trained on examples built from inaccurate API documentation. Key errors included a listed variable, sea-level pressure, that the API had never actually served, a hardcoded start year of 1960 when the archive begins in 1961, and incorrect timestamp format descriptions for climate mean data. Because training examples were written against the documentation rather than the live API, the model confidently generated well-formed but non-functional code for every affected query type. The incident highlights a systemic risk in fine-tuning workflows: documentation describes what a system is supposed to do, not necessarily what it does, and that gap can go undetected until someone tests the real endpoints.