![]() | |
#21
| |||
| |||
|
|
"Captain Paralytic" <paul_lautman (AT) yahoo (DOT) com> wrote in message news:1195033185.507438.249070 (AT) 57g2000hsv (DOT) googlegroups.com... On 13 Nov, 13:34, "Roy Hann" <specia... (AT) processed (DOT) almost.meat> wrote: Actually there's another aspect that hasn't been mentioned yet and that is the database design and the choice of indexes. My background to using databases is ISAM on System 36 and CICS/VSAM. When I design database tables (structure, indexes, ...), I'm always thinking of how it will be used and what the data will look like. I know that if I design it wrong, no optimzer in the world will ever be able to access the data efficiently. It seems to me that, programmers who have no appreciation of how to craft an efficient query, are unlikely to have given sufficient thought to this important aspect. I think this is starting to strain the definition of the term "programmer". No doubt in small projects you do have jacks-of-all-trades and many of them are just as good as you say. But even just moderately large projects will have way more programmers writing applications to someone else's database design. Whether the job titles distinguish them or not, the people doing the database design are not the same as the much larger number of people doing most of the coding. |
|
I don't see a great deal of difference between helping the optimizer by good design of database and helping it with good design of query. A good database design benefits all the programmers without them even being aware of it. They get the benefit of it without having to do anything special. They also automatically get the benefit of any future server-side performance enhancements. This is hugely significant. In July I went to one site and set up rule-based table partitioning. The application speeded up by a factor of more than 10 without any code changes. In September I went to another site confidently expecting to pull off the same trick and found I would have to re-implement the entire application to make it work, because their code was written so that it couldn't exploit new server-side features. |
|
And let's not forget platform-independence. I don't personally worship at application-portability alter, and I don't think many people really do. But even though it doesn't matter whether an application is platform-independents, programmers are better off being platform-independent. Roy |
#22
| |||||
| |||||
|
|
"Jerry Stuckle" <jstucklex (AT) attglobal (DOT) net> wrote in message news:KdadnbLW3LVyn6banZ2dnUVZ_o-mnZ2d (AT) comcast (DOT) com... Roy Hann wrote: Having to know a special, usually non-obvious, non-portable formulation for doing common tasks isn't a defect? What is "special, usually non-obvious, non-portable"? In MySQL, you can do it all in ANSI standard SQL. Portable to every database which supports ANSI SQL. Sure the syntax is portable. No one has ever argued that it isn't. But you just got through telling me that what is efficient SQL to one DBMS may not be efficient to another (and that is true). The whole conversation has been about efficiency from the start (look at the Subject heading), not syntax. I have nothing to say about syntax. |
|
But if you think a RDBMS should be able to optimize everything, Are you suggesting that isn't a desirable aspiration? Why should I want an RDBMS that doesn't if I could have one that does? No, the impossible is not a desirable aspiration. Reality should be, though. You are the one who wanted me to write my own DBMS. I just wanted to be able to rank real products so I could choose the best one. Who's being more realistic? |
|
then why don't you write your own? For the very simple reason that I wouldn't know how. But what I do know is how to compare existing products and rank them by how close to my ideal they get, so that I can choose the best of the many real products I can actually get/buy today. Then you shouldn't be complaining that programmers who DO know it well aren't getting it right. Perhaps it's a lot harder than you think - i.e. impossible - for them to get it right. First of all there is never a burden on any consumer to know how to design a better product before they ask for it. Do you know how to design a car? That didn't stop you wanting a better car than your first one though, did it? Secondly, I am not asking for the impossible. I said products already exist that do what I was talking about. I was not asking anyone to build a never-before-seen feature. |
|
SQL was the name given to the language component of System R, but it was derived from other, earlier projects at IBM and elsewhere, including a language called SQUARE. But I will concede this point. Where it came from is irrelevant to my main point that in the 21st century optimizers can reasonably be expected to be highly intelligent. Actually, not. Sure they got some ideas from SQUARE - but SEQUEL was a completely separate implementation. But if you want to say that by getting ideas from SQUARE SEQUEL was derived, then I could point out SQUARE got ideas from COBOL (which got ideas from Assembler...). As I said, I concede the point, although I struggle to see what COBOL and Assembler have to do with it. |
|
Sure. Experts will always be needed, but one should hope they'll be needed with ever-decreasing frequency and only for ever more complicated queries. The OP's query was, IMO, capable of a trivial optimization and there are products that you can use today that would have found it automatically. And you don't have to be an expert to learn how to write better SQL statements. Just a programmer. What an absurd assertion. What is the difference between a programmer who writes one correct SQL statement (like the OP) and a programmer who knows how to write a better one? Isn't that the very meaning of "expert"? Not at all. Expert programmers can write much more complicated SQL statements. This conversation is about the ability of optimizers to take a correct specification of a required result and generate an optimal execution plan. No one is talking about the limits of the complexity of the code programmers can write. But you do raise an important distinction. There are two kinds of expertise involved. One kind of expertise is having sufficient understanding to express a desired result, and the other is knowing which of the very many equivalent ways of expressing it will work efficiently. I say the first skill will always be valuable, but the value of the second is inversely proportional to how good the optimzer is. And one hopes optimizers are getting better all the time, so one also necessarily also hopes the second kind of expertise becomes less valuable. You do hope optimizers get better don't you? Roy |
#23
| ||||||
| ||||||
|
|
"Captain Paralytic" <paul_laut... (AT) yahoo (DOT) com> wrote in message news:1194956220.063305.125300 (AT) d55g2000hsg (DOT) googlegroups.com... On 13 Nov, 12:07, "Roy Hann" <specia... (AT) processed (DOT) almost.meat> wrote: I also expect that most working programmers have little or no interest in SQL, regard it as a distraction, |
|
That's why there are SQL programmers! I take it you mean *expert* SQL programmers? Sure, there are such people. But I suspect there are very many more |
|
programmers writing Java and Cobol and PHP and so on, who are compelled to use SQL but regard it as something other than a core skill, and know just enough to get by. They don't want to take the time to become highly proficient with SQL. They dislike it; they probably feel it gets in the way more than it helps, and if they have to repeatedly reformulate a query looking for that one special way of expressing it so it works tolerably well, then they would (rightly) think that's just voo-doo and hate SQL even more. |
|
SQL was intended to be a goal-oriented language. The idea was (explicitly) to allow the optimizer to discern the essential meaning of the query--no matter how it was expressed--and come up with an efficient way of producing the requested result. That's how it is supposed to work, and lots of products achieve that to a remarkable degree. |
|
Flipping it around, if we had a perfect SQL engine, no one would ever ask to add a feature so they could write an equivalent query that would be slower! :-) |
|
Expert SQL programmers are actually a bad thing. We shouldn't want to want them. Roy |
#24
| ||||
| ||||
|
|
"Jerry Stuckle" <jstuck... (AT) attglobal (DOT) net> wrote in message news:nYKdnbGMULq9MKTanZ2dnUVZ_sqinZ2d (AT) comcast (DOT) com... Roy Hann wrote: [] SQL was intended to be a goal-oriented language. The idea was (explicitly) to allow the optimizer to discern the essential meaning of the query--no matter how it was expressed--and come up with an efficient way of producing the requested result. That's how it is supposed to work, and lots of products achieve that to a remarkable degree. No, SQL (Structured Query Language) was created to access data in IBM's System R relational database. And back in the early 70's, optimizers were a pipe dream. First of all that doesn't refute anything I said. |
|
... Secondly SQL (nee SEQUEL) predates System R by many years--almost a decade. |
|
... SQL was added to System R very late in the day. Thirdly there were quite reasonable RDBMS optimizers by the late 70s. And fourthly, we are in the 21st century now and what was dreamt of 30 years ago is eminently possible now--as demonstrated daily by the better products you can actually buy or download today. |
|
Flipping it around, if we had a perfect SQL engine, no one would ever ask to add a feature so they could write an equivalent query that would be slower! :-) Expert SQL programmers are actually a bad thing. We shouldn't want to want them. And if we had perfect computer systems, we would never need programmers. People would be able to just speak into a microphone and get the response to their questions. Programmers are actually a bad thing. We shouldn't want to want them. Maybe you think that's whimsical, but actually that is exactly what I think, in absolute, complete seriousness. Roy |
#25
| |||
| |||
|
|
On 13 Nov, 13:34, "Roy Hann" <specia... (AT) processed (DOT) almost.meat> wrote: "Captain Paralytic" <paul_laut... (AT) yahoo (DOT) com> wrote in message news:1194956220.063305.125300 (AT) d55g2000hsg (DOT) googlegroups.com... On 13 Nov, 12:07, "Roy Hann" <specia... (AT) processed (DOT) almost.meat> wrote: I also expect that most working programmers have little or no interest in SQL, regard it as a distraction, That's why there are SQL programmers! I take it you mean *expert* SQL programmers? Sure, there are such people. But I suspect there are very many more programmers writing Java and Cobol and PHP and so on, who are compelled to use SQL but regard it as something other than a core skill, and know just enough to get by. They don't want to take the time to become highly proficient with SQL. They dislike it; they probably feel it gets in the way more than it helps, and if they have to repeatedly reformulate a query looking for that one special way of expressing it so it works tolerably well, then they would (rightly) think that's just voo-doo and hate SQL even more. SQL was intended to be a goal-oriented language. The idea was (explicitly) to allow the optimizer to discern the essential meaning of the query--no matter how it was expressed--and come up with an efficient way of producing the requested result. That's how it is supposed to work, and lots of products achieve that to a remarkable degree. Actually there's another aspect that hasn't been mentioned yet and that is the database design and the choice of indexes. My background to using databases is ISAM on System 36 and CICS/VSAM. When I design database tables (structure, indexes, ...), I'm always thinking of how it will be used and what the data will look like. I know that if I design it wrong, no optimzer in the world will ever be able to access the data efficiently. It seems to me that, programmers who have no appreciation of how to craft an efficient query, are unlikely to have given sufficient thought to this important aspect. I don't see a great deal of difference between helping the optimizer by good design of database and helping it with good design of query. |
#26
| |||
| |||
|
|
This conversation is about the ability of optimizers to take a correct specification of a required result and generate an optimal execution plan. |
|
No one is talking about the limits of the complexity of the code programmers can write. But you do raise an important distinction. There are two kinds of expertise involved. One kind of expertise is having sufficient understanding to express a desired result, and the other is knowing which of the very many equivalent ways of expressing it will work efficiently. I say the first skill will always be valuable, but the value of the second is inversely proportional to how good the optimzer is. And one hopes optimizers are getting better all the time, so one also necessarily also hopes the second kind of expertise becomes less valuable. |
|
You do hope optimizers get better don't you? Roy |
#27
| |||
| |||
|
|
On Nov 14, 11:36 am, "Roy Hann" <specia... (AT) processed (DOT) almost.meat wrote: [] This conversation is about the ability of optimizers to take a correct specification of a required result and generate an optimal execution plan. So you can dream of optimizers getting better, but they are going against a fundamental limit. There is a point they cannot do any better. |
|
No one is talking about the limits of the complexity of the code programmers can write. But you do raise an important distinction. There are two kinds of expertise involved. One kind of expertise is having sufficient understanding to express a desired result, and the other is knowing which of the very many equivalent ways of expressing it will work efficiently. I say the first skill will always be valuable, but the value of the second is inversely proportional to how good the optimzer is. And one hopes optimizers are getting better all the time, so one also necessarily also hopes the second kind of expertise becomes less valuable. Keep dreaming. |
|
[snip] but they are stuck against a limit. For any given query, they can only get incrementally better until they reach that limit and then not better at all. It's kind of like the Speed of light in physics. Unless you have some tacheons in your pocket, you can't get there any faster. |
#28
| |||||||||
| |||||||||
|
|
On Nov 13, 8:34 am, "Roy Hann" <specia... (AT) processed (DOT) almost.meat wrote: "Captain Paralytic" <paul_laut... (AT) yahoo (DOT) com> wrote in message news:1194956220.063305.125300 (AT) d55g2000hsg (DOT) googlegroups.com... On 13 Nov, 12:07, "Roy Hann" <specia... (AT) processed (DOT) almost.meat> wrote: I also expect that most working programmers have little or no interest in SQL, regard it as a distraction, 99.7% of all statistics are made up. I suspect this comment from the "Captain" is too. |
|
That's why there are SQL programmers! I take it you mean *expert* SQL programmers? Sure, there are such people. But I suspect there are very many more and Roy joins in with his unsupported claim. Two people said it so it must be true! |
|
They dislike [SQL]; they probably feel it gets in the way more than it helps, and if they have to repeatedly reformulate a query looking for that one special way of expressing it so it works tolerably well, then they would (rightly) think that's just voo-doo and hate SQL even more. And it is sad that they feel that way. They possibly think programming in only one language, like java or COBOL, is "A good thing". And many poeple around the world think Americans are self-centered. How much moreso are these kinds of programmers. |
|
SQL was intended to be a goal-oriented language. The idea was (explicitly) to allow the optimizer to discern the essential meaning of the query--no matter how it was expressed--and come up with an efficient way of producing the requested result. That's how it is supposed to work, and lots of products achieve that to a remarkable degree. Wrong. |
|
Optimization is a late addition to SQL. |
|
It was originally intended to be a non-programmer's programming language. |
|
(The fact that SQL had a nice translation to relational logic which was being developed about the same time only helped it along.) |
|
Flipping it around, if we had a perfect SQL engine, no one would ever ask to add a feature so they could write an equivalent query that would be slower! :-) We are still waiting for the DWIMNWIS computer. I think it will be a long wait. (DWIMNWIS = Do What I Mean, Not What I Say) |
|
Expert SQL programmers are actually a bad thing. We shouldn't want to want them. To the extent that we have people that are Expert SQL programmers and unable to program in anything else, I would agree that this is a bad thing. Otherwise, I think your optimizer arguement would apply to about any programming language. |
#29
| |||
| |||
|
|
Actually there's another aspect that hasn't been mentioned yet and that is the database design and the choice of indexes. My background to using databases is ISAM on System 36 and CICS/VSAM. When I design database tables (structure, indexes, ...), I'm always thinking of how it will be used and what the data will look like. I know that if I design it wrong, no optimzer in the world will ever be able to access the data efficiently. It seems to me that, programmers who have no appreciation of how to craft an efficient query, are unlikely to have given sufficient thought to this important aspect. I don't see a great deal of difference between helping the optimizer by good design of database and helping it with good design of query. |
#30
| |||
| |||
|
|
On Nov 12, 8:52 pm, Dean.Brot... (AT) gmail (DOT) com wrote: I'm hoping some SQL gurus read this and help me optimize my table/ query. ![]() The table is shown below: CREATE TABLE IF NOT EXISTS PACKAGE_TABLE ( ID BIGINT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT, TAG_ID BIGINT UNSIGNED NOT NULL, LAST_UPDATE TIMESTAMP, JOB_NAME MEDIUMTEXT, STATE TEXT, ERROR_CODES INT UNSIGNED, OPERATOR MEDIUMTEXT, TAG_FIRMWARE TINYTEXT, . . . PLUS 5 OTHER TEXT FIELDS NOT IMPORTANT FOR THIS DICSUSSION ) In the table I will be storing multiple records keyed by the same TAG_ID. Essientlly every iteraction of each tag is stored and thus I can recover a tag's history. For an important report I want to query for the last update for each TAG_ID. I have come up with the following: SELECT * FROM PACKAGE_TABLE t1 WHERE JOB_NAME = 'Some Job' AND LAST_UPDATE = (SELECT MAX(t2.LAST_UPDATE) FROM PACKAGE_TABLE t2 where t1.TAG_ID = t2.TAG_ID) This query works but on large tables (10000+ tag ids) the query really slows. Does anyone know of a more efficient way to format the table/ query for increased speed. No guarantees, but try writing it as a join instead: select * from package_table p1 join (select p2.tag_id, max(p2.last_update) last_update from package_table p2 group by p2.tag_id) x on (p1.tag_id = x.tag_id and p1.last_update = x.last_update) where job_name = 'Some Job' |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |