Giter Club home page Giter Club logo

mysqlfenwick's Introduction

MySQLFenwick

What

Trying desperately to get O(lg^2 n) cumulative sum search out of MySQL by shoving the entire binary search and Fenwick cumulative sum operation into a single query.

How

MySQL has a particular disdain for looping procedures, whose performance suffers dramatically with the overhead from separated SELECT statements, so trying to condense it into a single query is a natural path to attempt instead.

conditional_advance and fenwick_one_query both act on a table `entries` constructed as:

CREATE TABLE entries (
    id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    weight DECIMAL(9, 3),
    fenwick DECIMAL(9, 3)
) ENGINE=MEMORY;

with the MEMORY engine providing O(1) search time. weight is added as a convenience for the initial construction; in practice fenwick alone would store all of the data in the table. build_fenwick is provided to build the Fenwick tree from values stored in weight. Rows of id must be consecutive and increasing.

Unfortunately, MySQL's hatred towards efficient procedures is matched only by its disregard for side-effect accumulator predictability. Theoretically, conditional_advance shouldn't be necessary as its own function, as all it does is fetches the fenwick value of the requested row, provided that the row index is not 0. However, after dozens of test queries, no way was found to integrate it into the original operation other than to place it in a separate function.

While still ~40% faster than using the equivalent procudure, this queries lags far behind linear search, which executes in ~10% the time in the regime of 10^4 entries.

mysqlfenwick's People

Contributors

acrylic-origami avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.