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

  • SEARCH
  • Home
  • 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 4612884
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:28:00+00:00 2026-05-22T01:28:00+00:00

Say I’m designing a tool that would save code snippets either in a PostgreSQL/MySQL

  • 0

Say I’m designing a tool that would save code snippets either in a PostgreSQL/MySQL database or on the file system. I want to search through these snippets. Using a search engine like Sphinx doesn’t seem practical because we need exact text matches of code when searching code.

grep and ack and has always worked great, but storing stuff in a database makes a large collection of stuff more manageable in certain ways. I’m wonder what the relative performance of running grep recursively over a tree of directories is compared to running a query like SQL’s LIKE or MySQL’s REGEXP function over an equivalent number of records with TEXT blobs is.

  • 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. Editorial Team
    Editorial Team
    2026-05-22T01:28:01+00:00Added an answer on May 22, 2026 at 1:28 am

    If you’ve 1M files to grep through, you will (best I’m aware) go through each one with a regular expression.

    For all intents and purposes, you’re going to end up doing the same thing over table rows if you mass-query them using a LIKE operator or a regular expression.

    My own experience with grep is that I seldom look for something that doesn’t contain at least one full word, however, so you might be able to take advantage of a database to reduce the set in which you’re searching.

    MySQL has native full text search features, but I’d recommend against because they mean you’re not using InnoDB.

    You can read about those from Postgres here:

    http://www.postgresql.org/docs/current/static/textsearch.html

    After creating an index on a tsvector column, you can then do your “grep” in two steps, one to immediately find rows that might vaguely qualify, followed by another on your true criteria:

    select * from docs where tsvcol @@ :tsquery and (regexp at will);
    

    That will be significantly faster than anything grep can do.

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

Sidebar

Related Questions

Say I have the following file structure: app/ app.py controllers/ __init__.py project.py plugin.py If
Say that a page loads and the first thing I want to do is
Say I have a class Code defined like this, with a user specified type
Say I have a regex REGEX = re.compile('.*foo{') How would you write a unit
Say I have a simple WCF application that the client calls in order to
Say I have a listview control with several items in it. How would I
Say i have a tab control that displays data of various types, eg EditorTabViewModel
Say I have a class with synchronized methods. It's actually a class that uses
Say if i have a master page in that i have a button if
Say that you have a XHTML document in English but it has accented characters

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.